Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TinyMCE is adding new line ("\n") regardless of apply_source_formatting

TinyMCE is adding \n as well as paragraph tags to my text. Regardless of the apply_source_formatting settings value.

ie.

Source Text:

<blockquote><div class="cite">Person said:</div><div class="message"><p>ffgfgf</p></div></blockquote>

What TinyMCE Re-formats it to:

<blockquote>\n<div class=\"cite\">Person said:</div>\n<div class=\"message\">\n<p>ffgfgf</p>\n</div>\n</blockquote>\n<p id=\"mce_1\">&nbsp;</p>

How can I get TimyMCE to stop adding new line characters like this? It really messes with the formatting on the other end when the text is submitted.

like image 861
Douglas Gaskell Avatar asked Dec 19 '22 17:12

Douglas Gaskell


1 Answers

Investigating the source code of TinyMce I've found, that in the Writer.js (now Writer.ts) class, the setting that is checked before inserting \n is called indent.

 /**
 * Writes the a end element such as </p>.
 *
 * @method end
 * @param {String} name Name of the element.
 */
end: function(name) {
    var value;

    html.push('</', name, '>');

    if (indent && indentAfter[name] && html.length > 0) {
        value = html[html.length - 1];

        if (value.length > 0 && value !== '\n') {
            html.push('\n');
        }
    }
},

So adding indent: false to the settings object seems to fix it.

tinymce.init({
  selector: 'textarea',  // change this value according to your HTML
  indent: false,
});

I'd still classify this as a rather hackish fix as the indent-setting is not documented anywhere.

like image 85
oBusk Avatar answered Dec 28 '22 07:12

oBusk