[ckeditor]:如何仅禁用一种CSS样式

时间:2015-08-12 11:47:05

标签: ckeditor config ckeditor4.x

HY,

有没有办法只允许

  

display:inline-block;并显示:block;

并允许其他显示规则?如果我将 {display }添加到config.disallowedContent规则中,则不允许所有显示样式(也包括显示表,内联和其他)。

Tnx回答。

1 个答案:

答案 0 :(得分:2)

Advanced Content Filter无法过滤样式属性值,但CKEDITOR.htmlDataProcessor为您提供了一些极少的界面(JSFiddle):

var filterDisplayProperty = {
    attributes: {
        style: function( value, element ) {
            value = CKEDITOR.tools.parseCssText( value, 1 );

            if ( value.display in { 'block': 1, 'inline-block': 1 } ) {
                delete value.display;
            }

            // If there's no CSS rules left, discard style attribute.
            return CKEDITOR.tools.writeCssText( value ) || false;
        }    
    }
};

CKEDITOR.replace( 'editor', {
    toolbar: [ [ 'Source' ], [ 'Undo', 'Redo' ], [ 'Bold', 'Italic', 'Underline' ], [ 'CreateDiv' ] ],
    on: {
        pluginsLoaded: function() {
            // Filter data that comes INTO the editor.
            this.dataProcessor.dataFilter.addRules( filterDisplayProperty ); 

            // Filter data that comes OUT of the editor.
            this.dataProcessor.htmlFilter.addRules( filterDisplayProperty );
        }
    }    
} );