无论apply_source_formatting如何,TinyMCE都会添加新行("\n")

Dou*_*ell 2 javascript tinymce

TinyMCE正在\n为我的文本添加段落标签.无论apply_source_formatting设置值如何.

即.

来源文字:

<blockquote><div class="cite">Person said:</div><div class="message"><p>ffgfgf</p></div></blockquote>
Run Code Online (Sandbox Code Playgroud)

TinyMCE将其重新格式化为:

<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>
Run Code Online (Sandbox Code Playgroud)

我怎样才能让TimyMCE停止添加这样的新行字符?提交文本时,它真的会混淆另一端的格式.

oBu*_*usk 7

调查我发现的TinyMce的源代码,在Writer.js(现在Writer.ts)类中,\n调用插入前检查的设置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');
        }
    }
},
Run Code Online (Sandbox Code Playgroud)

所以添加indent: false到设置对象似乎解决了它.

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

我仍然将其归类为一个相当严厉的解决方案,因为任何地方indent都没有记录设置.

  • 你是我的英雄。 (2认同)