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:

  1. Enable paste plugin.
  2. Add handler for parsing inserted text

So your TinyMCE code will look like:

      	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>|&nbsp;)\s*<\/p>/ig, "");

See more info on the official wiki

Tags: , ,

AddThis Social Bookmark Button

4 Responses to “Extra spacing in TinyMCE after pasting from Word”

  1. michel Says:

    Thanks, works fine.

  2. Jesse Says:

    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!!

  3. pascal Says:

    THANKS mate, I searched for the solution to the empty paragraphs in Tinymce for 1 hour before finally finding your magic regex!!!

  4. Jeanine Says:

    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 :)

Leave a Reply