1

On a Drupal 8 installation, with CKEditor enabled for Full HTML format, when I paste text from Word with cmd+V, the source code includes format that makes the code dirty.

Example:

<p><span style="font-size:12pt"><span style="line-height:115%"><span style="font-family:Helvetica">Lorem ipsum dolor.</span></span></span></p>

How can I force it to clean the code from Word?

0

Two options:

  • there is a special "Paste from Word"-button in CKeditor, add it to your toolbar
  • limit allowed HTML tags, it will strip unwanted tags attributes when saving the node (by default spans are allowed, but style attributes will be removed by default)

Both can be done in Configuration > Content authoring > Text formats and editors

  • "limit allowed HTML tags" worked for me, thanks @Hudri. "Paste from Word"-button dowsn't work in some browsers, for example in Chrome for Mac shows the error: "Your browser doesn't allow you to paste this way. Press ⌘+V to paste." – jmzea Oct 20 '17 at 8:16
  • Yes, I do get the same message when pasting in chrome for windows, but it did work in IE – Hudri Oct 20 '17 at 9:00
1

For reference, there was a backwards-compatibility break in CKEditor v4.6 - it removed some of its own paste-from-Word button's cleaning. See this discussion on the Drupal side: https://www.drupal.org/project/drupal/issues/2871539

Note comment #6 there offers another workaround - responding to the afterPasteFromWord CKEditor event in some custom Javascript and filtering exactly as desired.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.