[ckeditor]:如何只禁止一种 css 样式

[ckeditor]: How to disallow only one css style

嗨,

有没有办法只禁止

display: inline-block; and display: block;

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

谢谢你的回答。

Advanced Content Filter to filter style property values but CKEDITOR.htmlDataProcessor gives you some handful interface (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 );
        }
    }    
} );