在CKEditor 4.x有没有办法在初始化后获取允许的标签列表? [英] In CKEditor 4.x is there a way to get the list of allowed tags after initialization?

查看:521
本文介绍了在CKEditor 4.x有没有办法在初始化后获取允许的标签列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以在CKEDitor 4.x(精确到4.4.7)中获得所有允许的标签的列表之后,编辑器已使用所有插件进行初始化,所有 allowedContentRules disallowedContentRules 或任何其他数据过滤器已应用?



希望有这个列表,以便我可以将其传递到我们的后端白名单。我知道已经有一个白名单插件CKEditor,这将允许我指定相同的白名单在前端和后端,但恐怕我可能会错过一些标签使用在一些插件,可能会削弱他们。 p>

解决方案

可能 CKEDITOR.filter.allowedContent 是您要查找的内容。它可以从 editor.filter 属性访问。如何操作的小例子: https://jsfiddle.net/Comandeer/tb6f0g8r/

  CKEDITOR.replace('editor1',{
on:{
instanceReady:function(evt){
//它返回所有规则的数组,
//所以如果你想发送它到服务器,
//你可能需要JSON-ify。 b $ b var allowedContent = evt.editor.filter.allowedContent;
console.log(JSON.stringify(allowedContent,null,'\t'));
}
}
});

也许这种格式不如简单的字符串那样友好,但它传达你需要的所有信息。 p>

Is there a way to get a list of all allowed tags in CKEDitor 4.x (4.4.7 to be precise) after the editor has been initialized with all plugins, and all allowedContentRules and disallowedContentRules or any other datafilters have been applied?

I would like to have this list so that I can pass it on to our back-end for whitelisting. I know there is already a whitelist plugin for CKEditor which would allow me to specify the same whitelist on both front-end and back-end, but I'm afraid I may miss some tag used in some plugin which may cripple them.

解决方案

Probably CKEDITOR.filter.allowedContent is what you're looking for. It can be accessed from the editor.filter property. Small example of how to do it: 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' ) );
        }
    }
} );

Maybe that format is not as friendly as simple string, but it conveys all information you need.

这篇关于在CKEditor 4.x有没有办法在初始化后获取允许的标签列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆