我为需要能够手动设置rel
和target
的链接创建了一个自定义污点。但是,当加载具有这些属性的内容时,quill会剥离它们。我不知道为什么。
我创建了一个codepen来说明这个问题。
这是我的自定义污点:
const Inline = Quill.import('blots/inline')
class CustomLink extends Inline {
static create(options) {
const node = super.create()
node.setAttribute('href', options.url)
if (options.target) { node.setAttribute('target', '_blank') }
if (options.follow === 'nofollow') { node.setAttribute('rel', 'nofollow') }
return node
}
static formats(node) {
return node.getAttribute('href')
}
}
CustomLink.blotName = 'custom_link'
CustomLink.tagName = 'A'
Quill.register({'formats/custom_link': CustomLink})
我必须告诉奎尔允许某些属性吗?
发布于 2017-10-27 18:55:48
在从现有的超文本标记语言进行初始化时,奎尔将尝试从它构建数据模型,这是create()
、value()
和formats()
之间的对称性。考虑到create()
是如何实现的,您需要formats()
是这样的:
static formats(node) {
let ret = {
url: node.getAttribute('href'),
};
if (node.getAttribute('target') == '_blank') {
ret.target = true;
}
if (node.getAttribute('rel') == 'nofollow') {
ret.follow = 'nofollow';
}
return ret;
}
使用此更改的工作分支:https://codepen.io/quill/pen/xPxGgw
https://stackoverflow.com/questions/46973980
复制