在CKEditor 4.x中,有没有办法在初始化后获取允许的标签列表

In CKEditor 4.x is there a way to get the list of allowed tags after initialization?

本文关键字:获取 列表 标签 初始化 CKEditor 有没有      更新时间:2023-09-26
在使用

所有插件初始化编辑器并应用所有allowedContentRulesdisallowedContentRules或任何其他数据过滤器后,有没有办法在 CKEDitor 4.x(准确地说是 4.4.7)中获取所有允许的标签的列表?

我想拥有此列表,以便我可以将其传递给我们的后端以进行白名单。我知道CKEditor已经有一个白名单插件,它允许我在前端和后端指定相同的白名单,但我担心我可能会错过某些插件中使用的一些标签,这可能会削弱它们。

可能CKEDITOR.filter.allowedContent就是你要找的。客人可以从editor.filter访问。如何做到这一点的小例子:https://jsfiddle.net/Comandeer/tb6f0g8r/

CKEDITOR.replace( 'editor1', {
    on: {
        instanceReady: function( evt ) {
            // It returns the array of all rules,
            //so if you want to send it to the server,
            // you'll probably need to "JSON-ify" it.
            var allowedContent = evt.editor.filter.allowedContent;
            console.log( JSON.stringify( allowedContent, null, ''t' ) );
        }
    }
} );

也许这种格式不像简单的字符串那么友好,但它传达了您需要的所有信息。