作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的项目正在使用 QuillJS。我正在尝试添加自定义类属性。我希望我的链接能够没有类名,或者类名“自定义链接”。已阅读此处的文档 https://github.com/quilljs/parchment#class-attributor我写了这段代码:
const Parchment = Quill.import('parchment');
const CustomLinkClass = new Parchment.Attributor.Class('custom-link', 'custom-link', {
scope: Parchment.Scope.INLINE
});
Quill.register(CustomLinkClass, true);
<a class="custom-link" href="https://google.com">Hello</a>
时进入编辑器,类名被剥离。有人可以帮忙吗?
最佳答案
正如您在 Parchment Attributor Class 的源代码中看到的那样,这种属性也使用一个值来创建类。所以最终的类名应该是形式 class-value
.如果您想实现单一值类属性,您可能需要扩展基础 Parchment Attributor并制作您自己的归因者,或使用白名单仅允许一个值。或者你可以像 quill 那样为他的类(class)做前缀,给你的所有类(class)加上前缀( ql-align-center
、 ql-video
、 ql-color-red
等等)。
const Parchment = Quill.import('parchment');
const PrefixClass = new Parchment.Attributor.Class('prefix', 'prefix', {
scope: Parchment.Scope.INLINE,
whitelist: [ 'custom-link', 'another-class' ]
});
Quill.register(PrefixClass, true);
prefix-custom-link
和
prefix-another-class
. Quill 会识别并保留它们。
quill.format('prefix', 'custom-link');
关于javascript - QuillJS : Cannot register a custom class attributor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49501686/
我的项目正在使用 QuillJS。我正在尝试添加自定义类属性。我希望我的链接能够没有类名,或者类名“自定义链接”。已阅读此处的文档 https://github.com/quilljs/parchme
我是一名优秀的程序员,十分优秀!