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

怎甘沉沦 提交于 2019-12-02 07:20:29

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/35844420/in-ckeditor-4-x-is-there-a-way-to-get-the-list-of-allowed-tags-after-initializat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!