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

最新更新