QuillJS:无法注册自定义类的attributor

时间:2018-03-26 22:33:53

标签: javascript quill

我的项目正在使用QuillJS。我正在尝试添加自定义类来源。我希望我的链接能够没有类名或类名" custom-link"。在这里阅读了文档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>插入编辑器时,类名被剥离。有人可以帮忙吗?

此处有一个Quill Playground示例:https://codepen.io/anon/pen/qoPVxO

1 个答案:

答案 0 :(得分:1)

您可以在Parchment Attributor Class的源代码中看到,这种归因者还使用一个值来创建类。因此,最终的类名称应采用 reading other reading_set 0 12 23 1 1 13 15 1 2 23 72 1 3 9 23 2 4 10 15 2 5 67 99 2 6 23 68 3 的形式。如果要实现单个值类别的归因,则可能必须扩展基数Parchment Attributor并创建自己的归因者,或者使用白名单仅允许一个值。或者,您也可以像对他的班级一样,通过给所有班级加上前缀(class-valueql-align-centerql-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