alex-phillips
alex-phillips

Reputation: 868

CKeditor 4.8 not removing styles on paste

We recently upgrade our CKeditor to 4. (was a big jump, we were on I think 4.3) and how when a user pastes in code, the editor is not automatically removing styling, specifically font and text color. I do have forcePasteAsPlainText : true in my config, but I can reliably reproduce pasting in text that preserves the font color (ex: red) as it was in an email. How can I make it so all text pasted in is stripped of HTML styles?

Upvotes: 1

Views: 4639

Answers (2)

j.swiderski
j.swiderski

Reputation: 2445

Please check which CKEditor version you use. It can be found at the top of ckeditor/CHANGES.md file. If you are not using latest 4.8.0, please upgrade.

While there were some problems with forcePasteAsPlainText in earlier versions, having that option set and pasting HTML should filter it as expected in latest editor 4.8.0.

If you also wish to clear all MS Word formatting then just like @Wizard has written, you can remove the pastefromword plugin. Alternatively if you wish to remove only certain styles, you can use afterPasteFromWord event where you can get to pasted HTML through event.data.dataValue and change it the way you like.

Upvotes: 1

Wizard
Wizard

Reputation: 3151

I'm assuming that this happens when you use Paste from Word plugin, because according to forcePasteAsPlainText info:

Whether to force all pasting operations to insert on plain text into the editor, losing any formatting information possibly available in the source text.

Note: paste from word (dialog) is not affected by this configuration.

So, I would use forcePasteAsPlainText and disable this plugin with:

forcePasteAsPlainText : true,
removePlugins: 'pastefromword'

Upvotes: 3

Related Questions