2012-07-12 32 views
0

我使用jHtmlArea从用户获取一些HTML,一切都很好,但是当我尝试从其他网站粘贴一些文本时,它不会将换行符解码为<br/> altought它们在框中。这只发生在粘贴的文本中,手动输入的文本没有问题。jHtmlArea不处理贴换行

所以,当我想显示文本正确我使用类似:

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

但是,当我需要重新显示在jHtmlArea此相同的文字,供用户编辑它,它就会失去所有的换行。有谁知道如何解决这一问题?

回答

0

我最终使用它,有太多的错误,我没有时间修复。 无论如何,这里是我做了什么,以获得保存的文本,以正确显示换行符(请检查是否如果你打算使用这个“黑客”的话,在将它保存到db之前源是好的)

$(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\>')); 


});