tinymce setContent删除新行

时间:2012-08-08 10:50:55

标签: tinymce

如果我在textarea中预装了内容,那么我将新行转换为“br”标签。

但是,如果我尝试使用setContent函数动态设置内容(不粘贴)到tinymce textarea,则缺少新行。

我使用的是v.3.4.7,尝试了v.3.5.6(迄今为止的最新版本),即使在页面加载时也会删除新行。

<script type="text/javascript">
    tinyMCE.init({
        mode: "textareas",
        editor_selector: "EmailBody",
        theme: "advanced",
        language: "en",
        charLimit: 10,
        plugins: "table,advhr,advlink,insertdatetime,preview,print,contextmenu,paste,directionality",
        theme_advanced_buttons1_add: "fontselect,fontsizeselect",
        theme_advanced_buttons2_add: "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor",
        theme_advanced_buttons2_add_before: "pastetext,pasteword,separator",
        theme_advanced_buttons3_add_before: "tablecontrols,separator",
        theme_advanced_buttons3_add: "advhr,separator,ltr,rtl,separator",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_statusbar_location: "bottom",
        plugi2n_insertdate_dateFormat: "%Y-%m-%d",
        plugi2n_insertdate_timeFormat: "%H:%M:%S",
        paste_use_dialog: false,
        theme_advanced_resizing: false,
        theme_advanced_resize_horizontal: true,
        paste_auto_cleanup_on_paste: true,
        paste_convert_headers_to_strong: false,
        paste_remove_spans: true,
        width: "100%",
        paste_remove_styles: true,
        valid_elements: "a[href|target=_blank],strong/b,div[align],p,br,i,u",
        content_css: "/css/tinymce_bigger_default_font.css",
        forced_root_block: false,
        force_br_newlines: true,
        force_p_newlines: false,
        apply_source_formatting: false,
        remove_linebreaks: false,
        convert_newlines_to_brs: true
    });
</script>

function Click()
{
    var text = document.getElementById("preText").innerText;
    tinyMCE.activeEditor.setContent(text);
}

<pre id="preText">Text

Text
</pre>

结果必须如下:

Text

Text

但我得到了:

TextText

4 个答案:

答案 0 :(得分:8)

如何替换新行以打破初始内容集上的行:

convert_newlines_to_brsremove_linebreaks参数已从tinymce中删除(请查看您的tinymce源代码)。

要恢复convert_newlines_to_brs功能,请使用此代码(它取自先前版本的tinymce):

tinyMCE.init({
    setup : function(ed) {
        ed.onBeforeSetContent.add(function(ed, o) {
            if (o.initial) {
                o.content = o.content.replace(/\r?\n/g, '<br />');
            }
        });
    }
});

答案 1 :(得分:3)

请参阅我的解决方案。我创造了一个小小的小提琴:http://fiddle.tinymce.com/vTbaab

答案 2 :(得分:0)

您需要做的就是添加

tinyMCE.init({
        ...
        remove_linebreaks : false
});

在他们的help中很好地记录了这些内容。

答案 3 :(得分:0)

我尝试了许多其他方法来尝试让它发挥作用。它源于原始开发人员未正确声明帖子类型。

在:

'supports' => array('title','slug'),

在:

'supports' => array('title','slug','editor'),
相关问题