繁体   English   中英

在 Ckeditor 5 中创建链接

[英]Creating link in Ckeditor 5

这个插件我做错了什么?

editor.model.schema.register('section', {
    allowAttributes: ['class']
});
editor.model.schema.register('a', {
    allowAttributes: ['class', 'href', 'target', 'download']
});

editor.model.change(writer => {

    const section = writer.createElement('section', {
        class: 'button'
    });
    const link = writer.createElement('a', {
        href: 'https://dominio.com/file.pdf',
        target: '_blank',
        download: 'file.pdf'
    });

    writer.appendText('DOWNLOAD', link);
    writer.insert(link, section);

    editor.model.insertContent(section, editor.model.document.selection);

});

结果是:

<p>DOWNLAOD</p>

但它应该是:

<section class="button"><a href="https://dominio.com/file.pdf" download="file.pdf" targert="_blank">DOWNLOAD</a></section>

有谁知道我在 ckeditor 5 上创建这个插件哪里出错了?

我无法按照自己的意愿解决它,但我是这样做的:

editor.model.change(writer => {
  const link = writer.createText('DOWNLOAD', {
    linkHref: 'https://file_link'
  });

  editor.model.insertContent(link, editor.model.document.selection);
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM