Search code examples
javascriptckeditorckeditor4.x

How can   be escaped as   using CKEDITOR 4 config?


I have set ckeditor 4 with the following overrides set in config.js for entity handling

config.entities_greek = false;
config.entities_latin = false;
config.entities_additional = '#39,#160';    

The default for config.entities_additional is '#39'.

When I use the above configuration, the output encoding breaks - I get several &undefined; entities in the output.

Is this a defect in ckeditor? There appears to be a workaround:

config.entities_processNumerical = 'force'; 

but this has the undesirable effect of encoding all non-ascii characters as numerical entities.


Solution

  • I know you wanted this to be done with config.js, but if you haven't found a solution, it could be done like this (assuming a CKEDITOR instance named editor1):

    CKEDITOR.instances.editor1.on('instanceReady', function(evt) {              
        evt.editor.dataProcessor.htmlFilter.addRules({
            text: function(value) {
                return value.replace(/ /g, ' ');
            }
        });
    });