Search code examples
ckeditorckeditor4.x

CKEditor paste filter is not working for content pasted from Word


I'm looking for a way to filter content pasted into a CKEditor such that the paste filter is more restrictive than the active content filter. According to the documentation, a "paste filter" should do exactly that.

I've set up a simple jsfiddle to demonstrate. That fiddle is set with a paste filter of 'plain-text'

CKEDITOR.editorConfig = function(config) {
  config.pasteFilter = 'plain-text';
};
CKEDITOR.replace('editor1');

If I copy styled content from MS Word for Mac and paste it into the editor window, the styling is maintained. Based on the documentation, I expect it to be pasted as plain text. I've tried this in both Firefox and Chrome.

The fiddle is simply CKEditor 4.17.1 loaded from the CDN and a simple configuration. I must be doing something wrong or have mis-understood the docs.


Solution

  • I also use CKEditor 4.17.1, and found the solution in the docs. While the docs for pasteFilter do not explicitly mention any conditions of its application for plain-text for some reason, this article on content filtering mentions that it doesn't apply to content that comes from the editor:

    In browsers where it is possible to recognize whether the content comes (was copied or dragged) from an editor, the paste filter will be applied only to content that does not come from any editor.

    It made me think there should be an option to force this with editors too, and I found one - forcePasteAsPlainText:

    true – Pastes all content as plain text.

    false – Preserves content formatting.

    allow-word – Content pasted from Microsoft Word will keep its formatting while any other content will be pasted as plain text.

    Defaults to false.

    Which means that you have to use config.forcePasteAsPlainText = true together with config.pasteFilter = 'plain-text' to force it with Word.