Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paste from word with uppercase

I pasted text from Word into the CKEditor javascript library. Some part of this text is uppercase in Word.

When the "Paste From Word" popup appear, the text is correctly formatted (with uppercase) but if I inspect the element the text is wrapped in a <span style="text-transform:uppercase">.

Then when I click "Ok" the text is copied in the CKEditor field but it removes the <span> and my text is now lowercase.

Is it possible to preserve the uppercase ? Either by not removing the span or by converting the span to uppercase ?

like image 670
Mike Avatar asked Feb 25 '26 05:02

Mike


1 Answers

It is possible to preserve that span. It is removed because none of enabled CKEditor features does not allow for this style. However, you can extend the Advanced Content Filter which is responsible for filtering with your own rules:

// Allow span with text-transform style.
config.extraAllowedContent = 'span{!text-transform}';

You may also need to disable one of pasteFromWord* options:

config.pasteFromWordRemoveStyles = false;

Remeber to clear cache after changing config.js!

PS. It is also possible to transform text in that span to upper case and remove the span, but it would require some custom coding in CKEDITOR.htmlDataProcessor's filters.

like image 145
Reinmar Avatar answered Feb 26 '26 17:02

Reinmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!