话不多说,先上个代码:

    1. import Quill from "quill";
    2. // 插入的图片要支持在新标签页中打开,没有提供相应的API,因此直接覆盖image的create方法
    3. // https://github.com/quilljs/quill/blob/develop/formats/image.js
    4. var Image = Quill.import("formats/image");
    5. const imageCreate = Image.create;
    6. Image.create = function(value) {
    7. // 执行原本的create方法
    8. const node = imageCreate.call(Image, value);
    9. // 添加onclick属性
    10. node.setAttribute(
    11. "onclick",
    12. `(function(){window.open('${value}', '_blank')}())`
    13. );
    14. // 遵循原create方法返回node
    15. return node;
    16. };