Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove /n/r in tinyMCE

Tags:

r

tinymce

I have a scenario where I have to read the pagesource of the html page and save it as a string. I have to retreive this page source in tinyMCE. When i setcontent of tinyMCE to this string i get \r \n. I want them to appear as line breaks not as string. I tried replacing the strings with but it didn't help. Please if anyone could help

tinyMCE.init({
    // General options
    mode: "specific_textareas",
    theme: "advanced",
    width: "100%",
    plugins: "pagebreak,paste,fullscreen,visualchars",
    entity_encoding: "raw",
    remove_linebreaks: false,
    init_instance_callback: "customTinyMceInit",
    // Theme options
    theme_advanced_buttons1: "code,|,bold,italic,underline,|,sub,sup,|,charmap,|,fullscreen,|,bullist,numlist,|,pasteword",
    theme_advanced_buttons2: "",
    theme_advanced_buttons3: "",
    theme_advanced_buttons4: "",
    theme_advanced_toolbar_location: "top",
    theme_advanced_toolbar_align: "left",
    theme_advanced_statusbar_location: "bottom",
    valid_elements: "i,sub,sup",
    invalid_elements: "p, script",
    editor_deselector: "mceOthers"

});

function customTinyMceInit(inst) {
    if (window.opener != null && !window.opener.closed) {
        var parent = $(window.opener.document).contents();
        var Id = queryString["Id"];
        var Result = [];


        $.ajax({
            type: "POST",
            url: "/Modules/Management/OnlineTemplateCreation.aspx/GetTemplateByContentId",
            data: "{'Id':"+Id+"}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                Result.push(data.d);
                alert(Result[0]);
                tinyMCE.getInstanceById("RichTextBox").setContent(Result[0]);
            }



        });
like image 487
Khurram Zulfiqar Ali Avatar asked Jul 15 '15 10:07

Khurram Zulfiqar Ali


3 Answers

apply source formatting in init

tinyMCE.init({
        ...
        apply_source_formatting : true
});
like image 133
taimoor.janjua Avatar answered Oct 17 '22 08:10

taimoor.janjua


Try to replace '\r \n' characters with '< br >' in your response data.

function replaceLineBreaks(data) {
     var replacedData = data.replace("\r \n", "<br>");
     return replacedData;
}

Then try this:

tinyMCE.getInstanceById("RichTextBox").setContent(replaceLineBreaks(Result[0]));

Hope this helps.

like image 26
Wahaj Ahmed Ansari Avatar answered Oct 17 '22 06:10

Wahaj Ahmed Ansari


This works for [email protected]

    tinyMCE.init({
    forced_root_block: false,
    });

SOURCE: https://www.tinymce.com/docs/configure/content-filtering/#forced_root_block

like image 2
chifangjang Avatar answered Oct 17 '22 06:10

chifangjang