div に変換したい文字列がありますが、div を適切に閉じません。
私が使用している文字列の例は次のとおりです。
[quote]Quote by: user1 [quote]Quote by: user2 ads[/quote]Test[/quote]Testing 2.
これにより、次の結果が得られます。
<div class="quote" style="margin-left:10px;margin-top:10px;">
Quote by: user1
[quote]Quote by: user2 ads
</div>
Test[/quote]Testing 2.
ただし、内部引用符は正しく変換されません。
私のJavascript関数は次のようなものです:
function bbcode_parser(str) {
search = new Array(
/\[b\](.*?)\[\/b\]/g,
/\[i\](.*?)\[\/i\]/g,
/\[quote](.*?)\[\/quote\]/g,
/\[\*\]\s?(.*?)\n/g);
replace = new Array(
"<strong>$1</strong>",
"<em>$1</em>",
"<div class='quote' style='margin-left:10px;margin-top:10px;'>$1</div>");
for (i = 0; i < search.length; i++) {
str = str.replace(search[i], replace[i]);
}
return str;
}
JSFiddle
実際の動作を確認できるように、http:
//jsfiddle.net/gRaFW/2/を用意しました。
助けてください :)