QuillJS:无法注册自定义类归因者

问题描述 投票:2回答:1

我的项目正在使用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>时,将删除类名。有人可以帮忙吗?

这里有一个鹅毛笔游乐场示例:https://codepen.io/anon/pen/qoPVxO

javascript quill
1个回答
0
投票

您可以在Parchment Attributor Class的源代码中看到,这种归因者还使用一个值来创建类。因此,最终的类名称应采用class-value的形式。如果要获得单个值类别的归因,则可能必须扩展基数Parchment Attributor并创建自己的归因,或者使用白名单仅允许一个值。或者,您也可以像他的班级上的羽毛笔一样,为所有班级添加前缀(ql-align-centerql-videoql-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-linkprefix-another-class。羽毛笔将识别并保留它们。

您也可以这样实用地将此类之一添加到您的选择中:quill.format('prefix', 'custom-link');

© www.soinside.com 2019 - 2024. All rights reserved.