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\"> </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.
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\"> </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.
Share Improve this question asked May 13, 2016 at 8:28 Douglas GaskellDouglas Gaskell 10k12 gold badges80 silver badges135 bronze badges 2- I currently have the same issue. Did you manage to find a solution? – oBusk Commented Sep 13, 2016 at 14:56
- 1 I don't believe so. I eventually dropped my project. I'll need to go back and see if I ever found a solution or hack for ir. – Douglas Gaskell Commented Sep 13, 2016 at 18:21
1 Answer
Reset to default 20Investigating 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,
});
From documentation:
This option, which is on by default, adds a newline character — U+000A,
\n
— between closing and opening block elements when HTML is output usinggetContent()
and when HTML is rendered in the TinyMCE Preview dialog.Set
indent
tofalse
to get HTML output from TinyMCE without having any newline characters added.