话不多说,先上个代码:
import Quill from "quill";
// 插入的图片要支持在新标签页中打开,没有提供相应的API,因此直接覆盖image的create方法
// https://github.com/quilljs/quill/blob/develop/formats/image.js
var Image = Quill.import("formats/image");
const imageCreate = Image.create;
Image.create = function(value) {
// 执行原本的create方法
const node = imageCreate.call(Image, value);
// 添加onclick属性
node.setAttribute(
"onclick",
`(function(){window.open('${value}', '_blank')}())`
);
// 遵循原create方法返回node
return node;
};