问题描述
这个插件我怎么了?
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);
});