Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TinyMCE is adding &nbsp instead of the space when using the word paste

Tags:

tinymce

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.

like image 848
Milos Cuculovic Avatar asked Sep 03 '12 12:09

Milos Cuculovic


People also ask

Is TinyMCE free for commercial use?

Is TinyMCE free? Yes. The TinyMCE core editor is free to use for commercial and noncommercial purposes.

How do you value TinyMCE?

getContent() method. to add the TinyMCE script and text area, then we can get the value when the editor is initialized by writing: tinymce. init({ selector: '#mytextarea', setup(editor) { editor.


2 Answers

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

like image 196
Milos Cuculovic Avatar answered Sep 26 '22 17:09

Milos Cuculovic


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

Regards.

like image 38
Arek T. Avatar answered Sep 23 '22 17:09

Arek T.