0

jHtmlAreaを使用してユーザーから HTML を取得していますが、すべて問題ありませんが、他の Web サイトからテキストを貼り付けようとすると、改行がデコードされず<br/>、ボックス内にあることがわかりません。これはテキストを貼り付けた場合にのみ発生し、手動で入力したテキストは問題ありません。

したがって、テキストを正しく表示したい場合は、次のようなものを使用します。

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

しかし、ユーザーが編集できるように、この同じテキストを jHtmlArea に再表示する必要がある場合、すべての改行が失われます。これを修正する方法を知っている人はいますか?

4

1 に答える 1

0

最後に使用を中止しました。バグが多すぎて修正する時間がありません..とにかく、保存したテキストを改行で正しく表示するために行ったことは次のとおりです(保存する前にソースが適切かどうかを確認してください)この「ハック」を使用する予定がある場合は、データベースに送信してください)

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


});
于 2012-07-12T15:51:25.523 に答える