ckeditor - 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?
解决方案
我无法按照我的意愿解决它,但我是这样做的:
editor.model.change(writer => {
const link = writer.createText('DOWNLOAD', {
linkHref: 'https://file_link'
});
editor.model.insertContent(link, editor.model.document.selection);
});
推荐阅读
- excel - 查找工作表名称并获取工作表索引
- c - 如何使用 inet_aton() 将 IP 地址转换为二进制形式
- java - 如何计算图像中的面积
- sql - 最近 3 年 SQL 的查询和透视列
- xtext - 是否可以将参数从 MWE2 配置传递到 XTend
- debugging - 在 Erlang/OTP 中调试时如何修复“无效的梁文件或没有抽象代码”错误?
- python - 循环每一列并匹配该值,然后创建另一个数据框
- javascript - 为什么可以向对象添加嵌套字段但不能添加根字段?
- java - 为什么 Files.readAllBytes() 不接受编码参数?
- python-3.x - 如何在 PythonOCC 中将 3d 盒子缩小为 2d 正方形