In CKEditor 4.x is there a way to get the list of

2019-03-01 04:46发布

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条回答
祖国的老花朵
2楼-- · 2019-03-01 05:32

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.

查看更多
登录 后发表回答