6

I am using the TinyMCE editor and the paste from word function.

My problem is that when I have spaces, tinyMCE transform them in &nbsp and I would like to keep the normal space.

Is there a filtering function or something similar which can be used in tinyMCe.init which will do that?

Thank you.

2 Answers 2

12

I have found a soultion, I am not sure that's the proper one, but it works. In the tinyMCE.init, I added:

paste_auto_cleanup_on_paste : true,
    paste_postprocess : function(pl, o) {
        // remove extra line breaks
        o.node.innerHTML = o.node.innerHTML.replace(/ /ig, " ");
    }

Here is the entire tinyMCE init:

function addTinyMCE_Authors_AffiliationsWord() {
    jQuery('#dialog-authors_affiliations_parsing').tinymce({
        script_url: '/js/tiny_mce_3.2.7_jquery/jscripts/tiny_mce/tiny_mce.js',
        width: "800px",
        height: "250px",
        mode: "textarea",
        theme : "advanced",
        plugins : "paste",
        // Theme options
        theme_advanced_buttons1 : "pasteword",
        theme_advanced_buttons2 :"",
        theme_advanced_buttons3 :"",
        theme_advanced_buttons4 :"",
        theme_advanced_toolbar_location : "bottom",
        valid_elements : "p",
        paste_auto_cleanup_on_paste : true,
        paste_postprocess : function(pl, o) {
            // remove &nbsp
            o.node.innerHTML = o.node.innerHTML.replace(/ /ig, " ");
         }
     });
}

ENJOY...

1
  • If you have multiple spaces between words and you change the nbsp to a regular space (without the correct css defined) then the multiple spaces will render as a single space and this will not be a viable solution.
    – jnoreiga
    Commented Sep 21, 2017 at 16:05
6

have you tried to add: entity_encoding: 'raw' when initializing tinyMce? it helped in my case.

Regards.

1
  • this solution having another issue when adding spaces to the end of editor then it will ignore those spaces. Commented Dec 9, 2022 at 0:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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