Extra spacing in TinyMCE after pasting from Word
TinyMCE can add extra empty paragraphs when you insert text from Word. TinyMCE simply wraps each newline into paragraph.
To solve it you need to follow these steps:
- Enable
paste
plugin. - Add handler for parsing inserted text
So your TinyMCE code will look like:
tinyMCE.init({ ... plugins: "paste", paste_auto_cleanup_on_paste : true, paste_postprocess : function(pl, o) { // remove extra line breaks o.node.innerHTML = o.node.innerHTML.replace(/<p.*>\s*(<br>| )\s*<\/p>/ig, ""); } });
See more info on the official wiki
Tags: javascript, TinyMCE, Word
December 3rd, 2010 at 7:07 pm
Thanks, works fine.
March 9th, 2011 at 6:33 pm
Works perfectly. Not sure why this is default behavior for tinyMCE, since it totally screws up the original formatting of the document…
ANyway, thanks to yoU!!
June 17th, 2011 at 1:50 am
THANKS mate, I searched for the solution to the empty paragraphs in Tinymce for 1 hour before finally finding your magic regex!!!
February 22nd, 2013 at 9:23 pm
Thank you so much! Was wondering around aimlessly trying to figure out how to make this work for all the double-paragraph spacing in Word