ckeditor / ckeditor4

The best enterprise-grade WYSIWYG editor. Fully customizable with countless features and plugins.
https://ckeditor.com/ckeditor-4
Other
5.79k stars 2.47k forks source link

"cke_show_blocks_off" class from Show Blocks plugin is removed when entering Source mode due to default rules of htmldataprocessor #3543

Open spacevoyager78 opened 5 years ago

spacevoyager78 commented 5 years ago

Show Blocks plugin provides the option to exclude an element from being marked by it, by using a class "cke_show_blocks_off", as it was introduced here: https://dev.ckeditor.com/ticket/10884 However, such class is automatically removed when I go to Source mode due to default rules of htmldataprocessor: https://github.com/ckeditor/ckeditor4/blob/major/core/htmldataprocessor.js#L749

attributes: {
    'class': function( value ) {
        // Remove all class names starting with "cke_".
        return CKEDITOR.tools.ltrim( value.replace( /(?:^|\s+)cke_[^\s]*/g, '' ) ) || false;
    }
}

Go to https://jsfiddle.net/148xmv3j/1/. Initially, "cke_show_blocks_off" works and the first paragraph is not marked, but hit Source button and the "cke_show_blocks_off" class is removed. So, every time I go to Source mode, I have to manually insert the class. Using a negative lookahead fixes it: value.replace( /(?:^|\s+)(?!cke_show_blocks_off\s)cke_[^\s]*/g, '' );

Comandeer commented 5 years ago

It's more a feature request, as introducing support for source mode requires much work to allow only certain classes to be preserved between two modes and, at the same time, not expose internal classes in source mode.

Probably related to #3516, due to the need of tracking which part of HTML code corresponds to which part of WYSIWYG output.

spacevoyager78 commented 5 years ago

I found out that even without going to Source mode, the class disappears when I'm calling getData() when I want to save the contents. So, I'm unable to save the contents and reload them without losing this class.