Question

I'm using jHtmlArea to get some HTML from user, everything is good but when I try to paste some text from other websites, it doesn't decode newlines to <br/> altought they are in the box. This only happens with pasted text, manually entered text is fine.

So when I want to display text correctly I use something like:

@Html.Raw(Model.Text.Replace(Environment.NewLine, "<br/>"))

But when I need to redisplay this same text in jHtmlArea for user to edit it, it loses all newlines. Does anyone know how to fix this?

Was it helpful?

Solution

I droped using it in the end, there is so much bugs that I don't have the time to fix.. Anyway here is what I did to get saved text to display correctly with newlines (please check if the source is good before saving it to db if you plan on using this "hack")

$(document).ready(function () {

//Initialize JhtmlArea 

    $(".editor").htmlarea({
        toolbar: [
                    ["bold", "italic", "underline"],
                    ["orderedList", "unorderedList"],
                    ["link", "unlink"],
                 ]
    });

//Set id (id will be same for all instances)

    $("iframe").attr("id", "editor");

// Style hack

$("#editor").contents().find('body').css({ "font-family": "MS Shell Dlg", "font-size": "12px", "font-weight": "100" });

// Finally to newlines hack

 var html = $(".editor").htmlarea("toHtmlString");

 // I would od something like $(".editor").htmlarea("html", "");
 // But there is a bug since this function calls "pastHtml" internally 
 // which is a typo instead of
 // "pasteHtml" so it won't work

 $("#editor").contents().find('body').html("");
 $(".editor").htmlarea("pasteHTML", html.replace(/\n/g, '<br\>'));


});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top