Ven*_*iya 5 html text-editor image angularjs quill
当我上传图片时,只会保存其“ src”。我想为SEO添加备用文本和标题。我尝试在Quill文档中搜索模块,但找不到任何模块。
也许不是直接答案,但相关。以下是从全文 html 初始化时保留图像属性的解决方案。
解决方案1:
class ImageBlot extends Image {
static create(value) {
if (typeof value == 'string') {
return super.create(value);
} else {
return value;
}
}
static value(domNode) {
return domNode;
}
}
Quill.register(ImageBlot);
Run Code Online (Sandbox Code Playgroud)
解决方案2:
class ImageBlot extends Image {
static get ATTRIBUTES() {
return [ 'alt', 'height', 'width', 'class', 'data-original', 'data-width', 'data-height', 'style-data' ]
}
static formats(domNode) {
return this.ATTRIBUTES.reduce(function(formats, attribute) {
if (domNode.hasAttribute(attribute)) {
formats[attribute] = domNode.getAttribute(attribute);
}
return formats;
}, {});
}
format(name, value) {
if (this.constructor.ATTRIBUTES.indexOf(name) > -1) {
if (value) {
this.domNode.setAttribute(name, value);
} else {
this.domNode.removeAttribute(name);
}
} else {
super.format(name, value);
}
}
}
Quill.register(ImageBlot);
Run Code Online (Sandbox Code Playgroud)
您可以使用solution2指定属性白名单。
| 归档时间: |
|
| 查看次数: |
965 次 |
| 最近记录: |