Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When copying text from the web and pasting it into ckeditor, how can I prevent it from applying its own inline css?
Below is a mild example of what can happen.
Text being copied
<p><strong><span class="Apple-style-span" style="font-weight:normal;">On 15 February 2011, the Guardian reported that Rafid Ahmed Alwan al-Janabi, code-named 'Curveball' by U.S. intelligence officials, admitted to fabricating knowledge of Saddam Hussein's alleged biological weapons program. Despite clear warnings from CIA officials, the Bush administration used Mr. Janabi's information in public statements and reports to Congress that influenced its vote to authorize military force against Iraq. </span></strong></p>
Text after being pasted into ckeditor
<p><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-weight: 700; ">On 15 February 2011, the Guardian reported that Rafid Ahmed Alwan al-Janabi, code-named 'Curveball' by U.S. intelligence officials, admitted to fabricating knowledge of Saddam Hussein's alleged biological weapons program. Despite clear warnings from CIA officials, the Bush administration used Mr. Janabi's information in public statements and reports to Congress that influenced its vote to authorize military force against Iraq. </strong></p>
Comments
Comment #1
bryancasler CreditAttribution: bryancasler commentedHere is a better example where you can see the insane amount of CSS that is added. I've copied this text directly from inside the editor itself.
Text being copied from ckeditor
Text after pasted into ckeditor
Comment #2
TwoDThis is not a bug in Wysiwyg module, and also not in CKEditor (though they might be able to filter it out).
It's a WebKit problem that can be reproduced with a simple div with contenteditable=true: http://stackoverflow.com/questions/3306205/how-to-avoid-webkit-contented...
Found these bug reports which seem related to this:
https://bugs.webkit.org/show_bug.cgi?id=26937
https://bugs.webkit.org/show_bug.cgi?id=25006.
Comment #3
bryancasler CreditAttribution: bryancasler commentedMade this temporary work around to cleanup the output.
Comment #4
bryancasler CreditAttribution: bryancasler commentedI've also found enabling "Limit allowed HTML tags" on my "Text formats" page works to strip out inline CSS from being displayed.
Comment #5
TwoDYes, just remember that'll also remove any styling added by the editor for things like backround/foreground-color etc.
You might want to try the WYSIWYG FIlter module, it allows for much greater control over what tags and styles are filtered out.