我已经编写了一个自定义链接模块来处理内部链接等等。此外,该模块还向A标记添加了一些类,这样它们就可以不同地显示出来。但是,Quill一旦再次实例化类,就会删除该类。
我已经发现你需要一个定制的属性。但我不能让它起作用。
为了保持思维简单,我创建了沙箱(没有我的模块)。
以下是代码:
<!-- ... -->
<div id="editor">
<a href="/test" class="btn">Foo</a>
</div>
<!-- ... -->import Quill from "quill";
import "quill-paste-smart";
import "quill/dist/quill.snow.css";
const Parchment = Quill.import("parchment");
let LinkClass = new Parchment.Attributor.Class("link", "ql-link", {
scope: Parchment.Scope.INLINE,
whitelist: ["btn"]
});
Quill.register({ "attributors/class/link": LinkClass }, true);
new Quill("#editor", {
theme: "snow",
modules: {
toolbar: ["bold", "italic", "underline", "link", "clean"]
}
});发布于 2020-11-14 01:04:55
您还需要使用Inline类在Quill实例的一侧添加该元素。
下面是一个示例:
const Inline = Quill.import("blots/inline");
InternalLink.blotName = "internal_link";
InternalLink.className = "btn";
InternalLink.tagName = "A";
Quill.register({
"attributors/class/link": LinkClass,
"formats/internal_link": InternalLink
});
我不认为这些文档是有帮助的,但这里有一个可以帮助您的例子:
发布于 2020-11-15 10:44:59
不幸的是,公认的答案不能完全解决我的问题。
我正在寻找一种可能的方法来添加/保留多个类。
以下是最后的解决方案:
const Inline = Quill.import("blots/inline");
const ATTRIBUTES = ["href", "rel", "target", "class"];
class InternalLink extends Inline {
static create(value) {
let node = super.create(value);
node.setAttribute("href", value.href);
if (value.rel) node.setAttribute("rel", value.rel);
if (value.target) node.setAttribute("target", value.target);
if (value.class) node.setAttribute("class", value.class);
return node;
}
static formats(domNode) {
return ATTRIBUTES.reduce((formats, attribute) => {
if (domNode.hasAttribute(attribute)) {
formats[attribute] = domNode.getAttribute(attribute);
}
return formats;
}, {});
}
}
InternalLink.blotName = "internal_link";
InternalLink.tagName = "A";
Quill.register({
"formats/link": InternalLink
});
https://stackoverflow.com/questions/64633430
复制相似问题