小编j.e*_*j.e的帖子

有没有办法允许 CKEditor5 的所有 html 属性或使用通配符?

我正在设置 ckeditor5,但它删除了很多 html 属性。我想知道是否有一种方法可以允许所有属性而不需要一一指定,或者可以使用通配符指定它。

(例子)

editor.model.schema.extend('$block', { allowAttributes: 'on-*'}); //for onclick and other events
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止所做的方法,这有点乏味,因为我必须指定每个属性。

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';

export default class Extension extends Plugin {
    init() {
        const editor = this.editor;

        let allowedAttributes = [
            'id',
            'class'
        ];

        editor.model.schema.extend('$root', { allowAttributes: allowedAttributes });
        editor.model.schema.extend('$block', { allowAttributes: allowedAttributes });
        editor.model.schema.extend('$text', { allowAttributes: allowedAttributes });

        for (var i = 0; i < allowedAttributes.length; i++) {
            editor.conversion.attributeToAttribute({ model: allowedAttributes[i], view: allowedAttributes[i] });
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

javascript ckeditor5

6
推荐指数
1
解决办法
2023
查看次数

标签 统计

ckeditor5 ×1

javascript ×1