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

j.e*_*j.e 6 javascript ckeditor5

我正在设置 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)

Mat*_*hen 1

CKEditor 有一个单独的配置来启用所有 HTML 功能。添加该内容应该可以解决您的问题。

https://ckeditor.com/docs/ckeditor5/latest/features/general-html-support.html#enabling-all-html-features

htmlSupport: {
    allow: [
        {
            name: /.*/,
            attributes: true,
            classes: true,
            styles: true
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)