首页 > 解决方案 > Creating link in Ckeditor 5

问题描述

What am I doing wrong with this plugin?

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);

});

The result is being:

<p>DOWNLAOD</p>

But it should be:

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

Does anyone know where I'm going wrong in creating this plugin on ckeditor 5?

标签: ckeditorckeditor5

解决方案


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

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

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

推荐阅读