2012-07-12 1 views
0

사용자로부터 일부 HTML을 얻기 위해 jHtmlArea을 사용하고 있습니다. 모든 것이 좋지만 다른 웹 사이트의 일부 텍스트를 붙여 넣으려고하면 <br/>에 개렛을 디코드하지 않습니다. 이것은 붙여 넣은 텍스트에서만 발생하며 수동으로 입력 한 텍스트는 문제가 없습니다. 나는 텍스트를 표시 할 때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\>')); 


});