Đăng nhập
Latest topics
» Tôi sẽ đỗ đại học!by NgocPRO 6/11/2024, 8:37 am
» Kỷ niệm xưa của chúng ta
by nightWalker 9/2/2024, 6:49 pm
» Bị lệch khung cần người giúp đỡ
by webhuy28 7/10/2021, 10:34 pm
» [HỎI ĐÁP] Danh sách bạn bè không thể hiển thị
by anhdaodaica1 2/10/2021, 10:04 pm
» [HỎI ĐÁP] Thông tin tài khoản không thể lưu thay đổi
by anhdaodaica1 2/10/2021, 6:05 am
» Phim bố già full
by huy.pc52 24/8/2021, 12:20 am
» Xin code Box HTML cho Forumvi
by Larva 1/7/2021, 12:57 pm
» Hello Anh Em Chinh phục
by HoàngTửNaivip5p 28/5/2021, 5:03 am
» Trang chủ tin tức cập nhật HOT 2016
by kenbi05 1/1/2020, 11:02 pm
» Không Dang9 bài viết = hình ảnh được
by huy.pc52 30/11/2019, 10:52 am
» CHÚC ANH EM NĂM MỚI VUI VẺ TRÀNG ĐẦY HẠNH PHÚC
by sps.kủn 12/2/2019, 1:16 pm
» Skin CNTT-K3 2015 (Full Mod)[✔]
by kenbi05 6/7/2018, 12:30 am
» baivong, handsome,....
by sps.kủn 29/6/2018, 1:54 pm
» [SHARE] SKIN ĐHFM.V7 @PUNBB
by tonyhoaivu 2/5/2018, 2:37 pm
» Share Skin Xanh Dương Cùi Bắp
by tonyhoaivu 28/4/2018, 5:57 pm
» Xin Skin http://v1.hotrofm.net/
by tonyhoaivu 28/4/2018, 5:45 pm
» Xin Skin Rao Vặt
by tonyhoaivu 15/4/2018, 12:07 pm
» Làm Sao Để Xóa Khung Này
by tonyhoaivu 14/4/2018, 7:18 pm
» [Lập nhóm]Lập nhóm fm
by vietkanpy 31/3/2018, 11:53 am
» [Help] về server úp ảnh của phutu [✔]
by baivong 17/3/2018, 10:18 pm
» Đừng khóc cho “tôi – Chinh Phục!”…
by AnHung 27/2/2018, 5:33 pm
» [Share] Skin Diendandaihoc.com [ Punbb ] [✔]
by Lu Mờ 13/2/2018, 7:28 pm
» Mời mấy thím vào groups Forumotion Việt Nam.
by dang02315 13/2/2018, 12:40 am
» Có thể làm các kiểu giao diện được không?
by Lu Mờ 9/2/2018, 3:40 pm
» ltns chinhphuc.info
by Shinichi Kudo 27/1/2018, 2:27 am
Top posting users this week
No user |
[Share code] Trang tiện ích Convert HTML => BBCode
+3
Eagle8x
hunghsmn
[D]ark[R]aven
7 posters
Trang 1 trong tổng số 1 trang
[Share code] Trang tiện ích Convert HTML => BBCode
Thấy code này cũng hay hay ! Tiện lợi để convert những bài ở blog hay viết = HTML ! Vừa làm 4um thêm phong phú
Vào: Modules -> HTML pages management -> Tạo 1 trang nội dung sau
Chịu khó vào đây ViewSource nhé:
Vào: Modules -> HTML pages management -> Tạo 1 trang nội dung sau
Chịu khó vào đây ViewSource nhé:
- Code:
http://cafam.123.st/h19-page
Re: [Share code] Trang tiện ích Convert HTML => BBCode
Thử xem sao không được:
[code]<head>
<title>..:: C.A.F - Convert HTML ::..</title>
<link rel="shortcut icon" type="image/x-icon" href="http://mmstroe.summerhost.info/favicon.ico" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</head>
<script type="text/javascript" language="JavaScript">
function shrink(what)
{
IE = (document.all)
if (IE)
displaystyle = "block";
else
displaystyle = "table-cell";
var totalTDs = document.getElementsByTagName("TD").length;
var what2 = what + "shrink"; // change DIV for code
var what3 = what + "code"; // change TH for code
if (document.getElementById(what2).innerHTML == "[-]")
{
document.getElementById(what2).innerHTML = "[+]";
for(i=0; i < totalTDs; i++)
{
if (document.getElementsByTagName("TD")<i>.className == what)
{
http://document.getElementsByTagName("TD")[i].style.visibility='hidden';
document.getElementsByTagName("TD")[i].style.display='none';
}
}
http://document.getElementById("bbccol").width = "1";
http://document.getElementById("contable").width="50";
document.getElementById(what3).style.display="none";
}
else
{
document.getElementById(what2).innerHTML = "[-]";
for(i=0; i < totalTDs; i++)
{
if (document.getElementsByTagName("TD")[i].className == what)
{
http://document.getElementsByTagName("TD")[i].style.visibility='visible';
document.getElementsByTagName("TD")[i].style.display=displaystyle;
}
document.getElementById(what3).style.display=displaystyle;
}
}
http://document.getElementById("bbccol").width = "350";
} // end function shrink()
function ClipBoard()
{
Copied = document.fm.textbox.createTextRange();
Copied.execCommand("Copy");
document.fm.textbox.select();
} // end functuon ClipBoard()
function selectall()
{
document.fm.textbox.select();
} // end function selectall()
var htmltext; // variable to save the html data
var finishedtext; // the variable will hold the finished text
// so we know if we have to put textbox back
// to HTML before converting to another type
// pof code
function item(pos, font, face, size, color)
{
this.pos = pos;
this.font = font;
this.face = face;
this.size = size;
this.color = color;
}
fontlist = new item(50);
fontclose = new item(50);
anchorlist = new item(50);
textarealist = new item(20);
function do_font(fonttext)
{
var i = 0;
var j = 0;
var n;
var pos;
var subfonttext;
fonttext = fonttext.toUpperCase();
http://document.fm.textbox.value = fonttext;
for (pos = 0; pos != -1; pos)
{
pos = fonttext.indexOf("<FONT", pos);
http://document.fm.textbox.value = document.fm.textbox.value + pos;
if (pos != -1) // if <FONT is found
{
n = fonttext.indexOf(">", pos);
fontlist[i] = new item(0, 0, 0, 0, 0);
fontlist[i].pos = pos;
fontlist[i].font = 1;
subfonttext = fonttext.substring(pos, n);
if (subfonttext.search(/FACE/) != -1)
fontlist[i].face = 1;
else
fontlist[i].face = 0;
if (subfonttext.search(/SIZE/) != -1)
fontlist[i].size = 1;
else
fontlist[i].size = 0;
if (subfonttext.search(/COLOR/) != -1)
fontlist[i].color = 1;
else
fontlist[i].color = 0;
http://document.fm.textbox.value = document.fm.textbox.value + i +
//subfonttext + fontlist[i].font + fontlist[i].color + '.';
pos++;
i++;
} // end if <FONT is found
//i--; // so i equals the length of fontlist
} // end for
// Now find all closing font tags </FONT>
for (pos = 0; pos != -1; pos)
{
pos = fonttext.indexOf("</FONT>", pos++);
http://document.fm.textbox.value = document.fm.textbox.value + pos;
if (pos != -1) // if </FONT> found
{
http://document.fm.textbox.value = document.fm.textbox.value + "i=" + i + ".";
fontclose[j] = new item(0, 0, 0, 0, 0);
fontclose[j].pos = pos;
fontclose[j].font = 1;
for (ii = i-1; ii >= 0; ii--)
{
http://document.fm.textbox.value = document.fm.textbox.value + "h1.";
if (fontlist[ii].pos < pos)
{
http://document.fm.textbox.value = document.fm.textbox.value + "h2.";
if (fontlist[ii].font == 1)
{
http://document.fm.textbox.value = document.fm.textbox.value + "h3.";
fontlist[ii].font = 0;
fontclose[j].color = fontlist[ii].color;
fontclose[j].size = fontlist[ii].size;
fontclose[j].face = fontlist[ii].face;
ii = -1; // since we found it, exit for loop
} // end if opening FONT tag
} // end if
} // end for
pos++;
j++;
} // end if </FONT> found
else
{
fontclose[j] = new item(0, 0, 0, 0, 0);
fontclose[j].font = 0;
}
} // end for
//for (i = 0;fontclose[i].font != 0; i++)
// {
// document.fm.textbox.value = document.fm.textbox.value +
// fontclose[i].font + fontclose[i].color +
// fontclose[i].size + fontclose[i].face;
// }
//alert("hi");
} // end function do_font()
function do_anchor(fonttext)
{
var i = 0;
var j = 0;
var n;
var pos;
var subfonttext;
fonttext = fonttext.toUpperCase();
http://document.fm.textbox.value = fonttext;
for (pos = 0; pos != -1; pos)
{
pos = fonttext.indexOf("<A HREF", pos);
http://document.fm.textbox.value = document.fm.textbox.value + pos;
if (pos != -1) // if <A HREF is found
{
n = fonttext.indexOf(">", pos);
anchorlist[i] = new item(0, 0, 0, 0, 0);
//fontlist[i].pos = pos;
anchorlist[i].font = 1;
subfonttext = fonttext.substring(pos, n);
if (subfonttext.search(/MAILTO:/) != -1)
{
subfonttext = subfonttext.replace(/<A HREF=MAILTO:/, "");
subfonttext = subfonttext.replace(/\"/, "");
subfonttext = subfonttext.replace(/\'/, "");
anchorlist[i].pos = 1; // mailto: flag
subfonttext = subfonttext.toLowerCase();
anchorlist[i].face = subfonttext; // email address
}
else
{
anchorlist[i].pos = 2; // http: flag
}
http://document.fm.textbox.value = document.fm.textbox.value + i +
//subfonttext + fontlist[i].font + fontlist[i].color + '.';
pos++;
i++;
} // end if <A HREF is found
else
{
anchorlist[i] = new item(0, 0, 0, 0, 0);
anchorlist[i].pos = 0; // no more anchors flag
}
//i--; // so i equals the length of fontlist
} // end for
} // end function do_anchor()
// this function copies all the textarea data to strings
// to preserve its code exactly as it is and not change it
function do_textarea(fonttext)
{
var i = 0;
var j = 0;
var n;
var pos;
var subfonttext;
textareatext = fonttext; // need this to preserve case
fonttext = fonttext.toUpperCase();
http://document.fm.textbox.value = fonttext;
for (pos = 0; pos != -1; pos)
{
pos = fonttext.indexOf("<TEXTAREA", pos);
http://document.fm.textbox.value = document.fm.textbox.value + pos;
if (pos != -1) // if <TEXTAREA is found
{
n = fonttext.indexOf(">", pos);
pos = fonttext.indexOf("</TEXTAREA>", n);
if (pos != -1) // if </TEXTAREA> is found
{
textarealist[i] = new item(0, 0, 0, 0, 0);
textarealist[i].face = textareatext.substring(n+1, pos);
// notice that we copied the area from textareatext
// because it has not had its case changed to upper
//fontlist[i].pos = pos;
textarealist[i].pos = 1;
}
http://document.fm.textbox.value = document.fm.textbox.value + i +
//subfonttext + fontlist[i].font + fontlist[i].color + '.';
pos++;
i++;
} // end if <TEXTAREA is found
else
{
textarealist[i] = new item(0, 0, 0, 0, 0);
textarealist[i].pos = 0; // no more textareas flag
}
//i--; // so i equals the length of fontlist
} // end for
} // end function do_textarea()
function backtohtml()
{
document.fm.textbox.value = htmltext;
} // end function back2html()
function showoptions()
{
var codetype;
for (i = 0; i < 4; i++)
{
if (document.fm.codetype[i].checked)
codetype = document.fm.codetype[i].value;
}
document.getElementById('vboption').style.visibility = "hidden";
document.getElementById('ipboption').style.visibility = "hidden";
if (codetype == "vbcode")
document.getElementById('vboption').style.visibility = "visible";
else if (codetype == "ipb")
document.getElementById('ipboption').style.visibility = "visible";
} // end function showoptions()
function convert()
{
var bbcodetext = document.fm.textbox.value;
var codetype;
var vbcodeoption;
var ipbcodeoption;
for (i = 0; i < 4; i++)
{
if (document.fm.codetype[i].checked)
codetype = document.fm.codetype[i].value;
}
document.fm.test.value = codetype;
for (i = 0; i < 3; i++)
{
if (document.fm.option[i].checked)
vbcodeoption = document.fm.option[i].value;
}
for (i = 0; i < 3; i++)
{
if (document.fm.option1[i].checked)
ipbcodeoption = document.fm.option1[i].value;
}
// Check to see if current textbox is the same
// as what is stored in finishedtext. If so
// then revert back to HTML text
if (finishedtext == bbcodetext)
{
document.fm.textbox.value = htmltext;
bbcodetext = document.fm.textbox.value;
}
// copy the textbox.value into htmltext
htmltext = document.fm.textbox.value;
do_font(bbcodetext);
bbcodetext = bbcodetext.replace(/<SCRIPT[^>]*>/gi, "<TEXTAREA>");
bbcodetext = bbcodetext.replace(/<\/SCRIPT>/gi, "</TEXTAREA>");
do_textarea(bbcodetext);
// maybe they put spaces around the = . Remove them
bbcodetext = bbcodetext.replace(/ = /gi, "=");
// maybe they put quotes surrounding the value
// so look for =" and ">
bbcodetext = bbcodetext.replace(/=\"/gi, "=");
//bbcodetext = bbcodetext.replace(/\">/gi, ">");
// maybe they put single quote surrounding the value
// so look for =' and '>
bbcodetext = bbcodetext.replace(/=\'/gi, "=");
//bbcodetext = bbcodetext.replace(/\'>/gi, ">");
bbcodetext = bbcodetext.replace(/<param name=movie[^>]*value=/gi, "<movie=");
bbcodetext = bbcodetext.replace(/ BORDER=[^\'\">]*[\'\">]/gi, "");
//bbcodetext = bbcodetext.replace(/ BORDER=[^\'>]*\'/gi, " ");
bbcodetext = bbcodetext.replace(/ TARGET=[^\'\">]*[\'\">]/gi, "");
//bbcodetext = bbcodetext.replace(/ TARGET=[^\'>]*\'/gi, "");
bbcodetext = bbcodetext.replace(/ CLASSID=[^\'\">]*[\'\">]/gi, "");
//bbcodetext = bbcodetext.replace(/ CLASSID=[^\'>]*\'/gi, "");
bbcodetext = bbcodetext.replace(/ ID=[^\'\">]*[\'\">]/gi, "");
//bbcodetext = bbcodetext.replace(/ ID=[^\'>]*\'/gi, "");
bbcodetext = bbcodetext.replace(/ NAME=[^\'\">]*[\'\">]/gi, "");
//bbcodetext = bbcodetext.replace(/ NAME=[^\'>]*\'/gi, "");
//bbcodetext = bbcodetext.replace(/ ALIGN=[^\"]*\"/gi, "");
//bbcodetext = bbcodetext.replace(/ ALIGN=[^\']*\'/gi, "");
//bbcodetext = bbcodetext.replace(/ ALIGN=[^>]*>/gi, ">");
bbcodetext = bbcodetext.replace(/ STYLE=[^\'\">]*[\'\">]/gi, "");
//bbcodetext = bbcodetext.replace(/ STYLE=[^\'>]*\'/gi, "");
bbcodetext = bbcodetext.replace(/ CLASS=[^\'\">]*[\'\">]/gi, "");
//bbcodetext = bbcodetext.replace(/ CLASS=[^\'>]*\'/gi, "");
bbcodetext = bbcodetext.replace(/ ALT=[^\'\">]*[\'\">]/gi, "");
//bbcodetext = bbcodetext.replace(/ ALT=[^\'>]*\'/gi, "");
bbcodetext = bbcodetext.replace(/ TITLE=[^\'\">]*[\'\">]/gi, "");
do_anchor(bbcodetext);
http://document.fm.textbox.value = bbcodetext;
//alert('here');
bbcodetext = bbcodetext.replace(/<BR>/gi, "\r");
bbcodetext = bbcodetext.replace(/<BR \/>/gi, "\r");
bbcodetext = bbcodetext.replace(/<p>/gi, "\r\r");
bbcodetext = bbcodetext.replace(/<P [^>]*>/gi, "\r\r");
bbcodetext = bbcodetext.replace(/<CODE>/gi, "</span><table width="90%" cellspacing="1" cellpadding="0" border="0" align="center"><tr><td><span class="genmed"><b>Code:</b></span></td></tr><tr><td class="code"><div class="cont_code" curpos="0" maxpos="0" pageincrement="480" increment="10" collapsed="true">");
bbcodetext = bbcodetext.replace(/<\/CODE>/gi, "</div></td></tr></table><span class="postbody">");
bbcodetext = bbcodetext.replace(/<BLOCKQUOTE>/gi, "</span><table width="90%" cellspacing="1" cellpadding="0" border="0" align="center"><tr><td><span class="genmed"><b>Trích dẫn:</b></span></td></tr><tr><td class="quote">");
bbcodetext = bbcodetext.replace(/<\/BLOCKQUOTE>/gi, "</td></tr></table><span class="postbody">");
bbcodetext = bbcodetext.replace(/<UL[^>]*>/gi, "<ul>");
bbcodetext = bbcodetext.replace(/<\/UL>/gi, "</ul>");
bbcodetext = bbcodetext.replace(/<OL[^>]*>/gi, "<ol type="1">");
bbcodetext = bbcodetext.replace(/<\/OL>/gi, "</ol>");
bbcodetext = bbcodetext.replace(/<LI>/gi, "[*]");
//bbcodetext = bbcodetext.replace(/<A HREF=mailto:/gi, "");
//bbcodetext = bbcodetext.replace(/<A HREF/gi, "[url");
//bbcodetext = bbcodetext.replace(/<\/A>/gi, "[/url]");
// *** Jeff!! These two remarked statements are the solution
// to make a better converter:
// (.*?) = match any character except new line 0 or more times and remember the match
// ([\s\S]*?) = match \s any white space char once inclduing \n, \S match any non-white space char, *? any number of times or 0 times
//bbcodetext = bbcodetext.replace(/<A[\s\S]*?HREF=\"(.*?)\"[\s\S]*?>([\s\S]*?)<\/A>/gi, "[url=$1]$2[\/url]");
bbcodetext = bbcodetext.replace(/<IMG[\s\S]*?SRC=([\s\S]*?)\"[\s\S]*?>/gi, "[img]$1[\/img]");
bbcodetext = bbcodetext.replace(/<IMG[\s\S]*?SRC=([\s\S]*?)'[\s\S]*?>/gi, "[img]$1[\/img]");
//bbcodetext = bbcodetext.replace(/<IMG SRC=/gi, "[img]");
//bbcodetext = bbcodetext.replace(/.jpg[^>]*>/gi, ".jpg[/img]");
//bbcodetext = bbcodetext.replace(/.gif[^>]*>/gi, ".gif[/img]");
//bbcodetext = bbcodetext.replace(/.bmp[^>]*>/gi, ".bmp[/img]");
//bbcodetext = bbcodetext.replace(/.png[^>]*>/gi, ".png[/img]");
bbcodetext = bbcodetext.replace(/<BIG>/gi, "<strong>");
bbcodetext = bbcodetext.replace(/<\/BIG>/gi, "</strong>");
bbcodetext = bbcodetext.replace(/<B>/gi, "<strong>");
bbcodetext = bbcodetext.replace(/<\/B>/gi, "</strong>");
bbcodetext = bbcodetext.replace(/<U>/gi, "<u>");
bbcodetext = bbcodetext.replace(/<\/U>/gi, "</u>");
bbcodetext = bbcodetext.replace(/<I>/gi, "[i]");
bbcodetext = bbcodetext.replace(/<\/I>/gi, "</i>");
if (codetype == "bbcode")
{
bbcodetext = bbcodetext.replace(/<FONT Face[^\'\">]*[\'\">]/gi, "<FONT");
//bbcodetext = bbcodetext.replace(/<FONT Face[^\']*\'/gi, "<FONT");
//bbcodetext = bbcodetext.replace(/<FONT Face[^ ]* /gi, "<FONT ");
//bbcodetext = bbcodetext.replace(/ FACE=[^ ]*\ /gi, " ");
//bbcodetext = bbcodetext.replace(/ FACE=[^>]*>/gi, ">");
bbcodetext = bbcodetext.replace(/ FACE=[^\'\"]*[\'\"]/gi, "");
//bbcodetext = bbcodetext.replace(/ FACE=[^\']*\'/gi, ">");
//alert(bbcodetext);
//bbcodetext = bbcodetext.replace(/<\/FONT>/gi, "[/size][/color]");
} // end if bbcode
if (codetype == "vbcode")
{
bbcodetext = bbcodetext.replace(/<STRONG>/gi, "[highlight]");
bbcodetext = bbcodetext.replace(/<\/STRONG>/gi, "[/highlight]");
bbcodetext = bbcodetext.replace(/<TEXTAREA[^>]*>/gi, "[code1]");
bbcodetext = bbcodetext.replace(/<\/TEXTAREA>/gi, "[/code1]");
// <FONT STYLE="background-color:yellow> <-- for hightlighting
} // end if vbcode
if (codetype == "ipb")
{
bbcodetext = bbcodetext.replace(/<STRIKE>/gi, "[s]");
bbcodetext = bbcodetext.replace(/<\/STRIKE>/gi, "[/s]");
bbcodetext = bbcodetext.replace(/<TEXTAREA[^>]*>/gi, "[code3]");
bbcodetext = bbcodetext.replace(/<\/TEXTAREA>/gi, "[/code3]");
// <FONT STYLE="background-color:yellow> <-- for hightlighting
} // end if ipb
if (codetype == "bbcode" || codetype == "vbcode" ||
codetype == "ipb")
{
bbcodetext = bbcodetext.replace(/<PRE[^>]*>/gi, "</span><table width="90%" cellspacing="1" cellpadding="0" border="0" align="center"><tr><td><span class="genmed"><b>Code:</b></span></td></tr><tr><td class="code"><div class="cont_code" curpos="0" maxpos="0" pageincrement="480" increment="10" collapsed="true">");
bbcodetext = bbcodetext.replace(/<\/PRE>/gi, "</div></td></tr></table><span class="postbody">");
} // end if bbcode or vbcode
if (codetype == "bbcode" || codetype == "smf")
{
bbcodetext = bbcodetext.replace(/<TEXTAREA[^>]*>/gi, "[code2]");
bbcodetext = bbcodetext.replace(/<\/TEXTAREA>/gi, "[/code2]");
}
if (codetype == "smf" || codetype == "vbcode" ||
codetype == "ipb")
{
bbcodetext = bbcodetext.replace(/<FONT Face/gi, "[font");
bbcodetext = bbcodetext.replace(/ Face=/gi, "]<font face="");
//bbcodetext = bbcodetext.replace(/<\/FONT>/gi, "[/font">[/size][/color]");
bbcodetext = bbcodetext.replace(/<LEFT>/gi, "<div align="left">");
bbcodetext = bbcodetext.replace(/<\/LEFT>/gi, "</div>");
bbcodetext = bbcodetext.replace(/<CENTER>/gi, "<div style="margin:auto;text-align:center;width:100%">");
bbcodetext = bbcodetext.replace(/<\/CENTER>/gi, "</div>");
bbcodetext = bbcodetext.replace(/<RIGHT>/gi, "<div align="right">");
bbcodetext = bbcodetext.replace(/<\/RIGHT>/gi, "</div>");
} // end if smf or vbcode
if (codetype == "ipb" || codetype == "bbcode")
{
bbcodetext = bbcodetext.replace(/<STRONG>/gi, "<strong>");
bbcodetext = bbcodetext.replace(/<\/STRONG>/gi, "</strong>");
}
if (codetype == "smf")
{
// because smf does not have ordered list <OL> support
bbcodetext = bbcodetext.replace(/\[list=1\]/gi, "[list]");
bbcodetext = bbcodetext.replace(/<STRONG>/gi, "[glow=red,2,50]");
bbcodetext = bbcodetext.replace(/<\/STRONG>/gi, "[/glow]");
bbcodetext = bbcodetext.replace(/<STRIKE>/gi, "[s]");
bbcodetext = bbcodetext.replace(/<\/STRIKE>/gi, "[/s]");
bbcodetext = bbcodetext.replace(/<MARQUEE[^>]*>/gi, "[move]");
bbcodetext = bbcodetext.replace(/<\/MARQUEE>/gi, "[/move]");
bbcodetext = bbcodetext.replace(/<PRE>/gi, "[pre]");
bbcodetext = bbcodetext.replace(/<\/PRE>/gi, "[/pre]");
bbcodetext = bbcodetext.replace(/<HR[^>]*>/gi, "<hr />");
bbcodetext = bbcodetext.replace(/<object[^>]*width=/gi, "[flash=");
bbcodetext = bbcodetext.replace(/<object[^>]*height=/gi, "[flash=");
bbcodetext = bbcodetext.replace(/\" height=/gi, ",");
bbcodetext = bbcodetext.replace(/\' height=/gi, ",");
bbcodetext = bbcodetext.replace(/\" width=/gi, ",");
bbcodetext = bbcodetext.replace(/\' width=/gi, ",");
bbcodetext = bbcodetext.replace(/ width=/gi, ",");
bbcodetext = bbcodetext.replace(/ height=/gi, ",");
bbcodetext = bbcodetext.replace(/\<movie=/gi, "");
//bbcodetext = bbcodetext.replace(/<embed src=/gi, "");
bbcodetext = bbcodetext.replace(/.swf[^>]*>/gi, ".swf[/flash]");
bbcodetext = bbcodetext.replace(/<TABLE[^>]*>/gi, "<table>"); bbcodetext = bbcodetext.replace(/<TR[^>]*>/gi, "[tr]"); bbcodetext = bbcodetext.replace(/<TD[^>]*>/gi, "[td]"); bbcodetext = bbcodetext.replace(/<TH[^>]*>/gi, "[td]"); bbcodetext = bbcodetext.replace(/<\/TABLE>/gi, "</table>");
bbcodetext = bbcodetext.replace(/<\/TR>/gi, "[/tr]");
bbcodetext = bbcodetext.replace(/<\/TD>/gi, "[/td]");
bbcodetext = bbcodetext.replace(/<\/TH>/gi, "[/td]");
bbcodetext = bbcodetext.replace(/<SUP>/gi, "<sup>");
bbcodetext = bbcodetext.replace(/<\/SUP>/gi, "</sup>");
bbcodetext = bbcodetext.replace(/<SUB>/gi, "<sub>");
bbcodetext = bbcodetext.replace(/<\/SUB>/gi, "</sub>");
bbcodetext = bbcodetext.replace(/<TT>/gi, "[tt]");
bbcodetext = bbcodetext.replace(/<\/TT>/gi, "[/tt]");
bbcodetext = bbcodetext.replace(/<ABBR TITLE=/gi, "[acronym=");
bbcodetext = bbcodetext.replace(/<\/ABBR>/gi, "[/acronym]");
bbcodetext = bbcodetext.replace(/<ACRONYM TITLE=/gi, "[acronym=");
bbcodetext = bbcodetext.replace(/<\/ACRONYM>/gi, "[/acronym]");
} // end if smf
else
{
// table tags for everyone but smf
bbcodetext = bbcodetext.replace(/<TR[^>]*>/gi, "\r");
bbcodetext = bbcodetext.replace(/<TD[^>]*>/gi, " ");
bbcodetext = bbcodetext.replace(/<TH[^>]*>/gi, " ");
bbcodetext = bbcodetext.replace(/<\/TR>/gi, " ");
bbcodetext = bbcodetext.replace(/<\/TD>/gi, " ");
bbcodetext = bbcodetext.replace(/<\/TH>/gi, " ");
}
// font size and color tags
bbcodetext = bbcodetext.replace(/<FONT SIZE=/gi, "[size=");
bbcodetext = bbcodetext.replace(/<FONT color=/gi, "[color=");
// maybe they put the size and color in one font statement
// so look for SPACE color and SPACE size
bbcodetext = bbcodetext.replace(/ color=/gi, "][color=");
bbcodetext = bbcodetext.replace(/ size=/gi, "][size=");
// The following for loop is for /FONT tags
// we are removing global search because we have to remove
// each </FONT> tag one at a time because some are closing
// [color], [size], or [font]
var fonttag;
for (i = 0; fontclose[i].font != 0; i++)
{
fonttag = "";
if (codetype == "smf" || codetype == "vbcode" ||
codetype == "ipb")
if (fontclose[i].face == 1)
fonttag = "</font>";
if (fontclose[i].color == 1)
fonttag = fonttag + "</font>";
if (fontclose[i].size == 1)
fonttag = fonttag + "[/size]";
bbcodetext = bbcodetext.replace(/<\/FONT>/i, fonttag);
} // end for
// The following for loop is to search anchor tags
// to have the right closing for mailto or http.
// It also does </A> tags
// we remove the global case in the replace function
for (i = 0; anchorlist[i].pos != 0; i++)
{
if (anchorlist[i].pos == 2) // if URL
{
bbcodetext = bbcodetext.replace(/<A HREF/i, "[url");
bbcodetext = bbcodetext.replace(/<\/A>/i, "[/url]");
} // end if URL
if (anchorlist[i].pos == 1) // if mailto:
{
if (codetype == "bbcode")
bbcodetext = bbcodetext.replace(/<A HREF[^<]*<\/A>/i, anchorlist[i].face);
else // if codetype is smf or vbcode
{
bbcodetext = bbcodetext.replace(/<A HREF=MAILTO:/i, "[email=");
bbcodetext = bbcodetext.replace(/<\/A>/i, "[/email]");
}
} // end if mailto:
} // end for loop for anchor tags
// This replaces all remaining HTML code between < and >
//bbcodetext = htmltext.replace(/<[^>]*>/g, "");
bbcodetext = bbcodetext.replace(/<[^>]*>/g, "");
// This will convert all > into ] because we left
// some open up top such as removing <font size
// and <UL
bbcodetext = bbcodetext.replace(/>/g, "]");
bbcodetext = bbcodetext.replace(/\'>/g, "]");
bbcodetext = bbcodetext.replace(/\">/g, "]");
bbcodetext = bbcodetext.replace(/\']/g, "]");
bbcodetext = bbcodetext.replace(/\"]/g, "]");
// The following for loop searches through all textareas.
// It takes place after all < > tags have been removed
// because it needs to go back in and put all the data
// back into the <TEXTAREA></TEXTAREA> tags unchanged.
// For that we search for [code1] & [code2]
for (i = 0; textarealist[i].pos != 0; i++)
{
if (textarealist[i].pos == 1) // if TEXTAREA
{
//alert("hi");
// turn textarea to Vb Codes [php] tag
if (vbcodeoption == "php")
bbcodetext = bbcodetext.replace(/\[code1\][\w\W]*?\[\/code1\]/i, "[php]" + textarealist[i].face + "[/php]");
if (vbcodeoption == "code")
bbcodetext = bbcodetext.replace(/\[code1\][\w\W]*?\[\/code1\]/i, "</span><table width="90%" cellspacing="1" cellpadding="0" border="0" align="center"><tr><td><span class="genmed"><b>Code:</b></span></td></tr><tr><td class="code"><div class="cont_code" curpos="0" maxpos="0" pageincrement="480" increment="10" collapsed="true">" + textarealist[i].face + "</div></td></tr></table><span class="postbody">");
if (vbcodeoption == "html")
bbcodetext = bbcodetext.replace(/\[code1\][\w\W]*?\[\/code1\]/i, "[html]" + textarealist[i].face + "[/html]");
if (ipbcodeoption == "sql")
bbcodetext = bbcodetext.replace(/\[code3\][\w\W]*?\[\/code3\]/i, "[sql]" + textarealist[i].face + "[/sql]");
if (ipbcodeoption == "code")
bbcodetext = bbcodetext.replace(/\[code3\][\w\W]*?\[\/code3\]/i, "</span><table width="90%" cellspacing="1" cellpadding="0" border="0" align="center"><tr><td><span class="genmed"><b>Code:</b></span></td></tr><tr><td class="code"><div class="cont_code" curpos="0" maxpos="0" pageincrement="480" increment="10" collapsed="true">" + textarealist[i].face + "</div></td></tr></table><span class="postbody">");
if (ipbcodeoption == "html")
bbcodetext = bbcodetext.replace(/\[code3\][\w\W]*?\[\/code3\]/i, "[html]" + textarealist[i].face + "[/html]");
// turn textarea to bbcode & smf [code] tag
bbcodetext = bbcodetext.replace(/\[code2\][\w\W]*?\[\/code2\]/i, "[code]" + textarealist[i].face + "[/code]");
} // end if TEXTAREA
} // end for loop for textarea tags
// put converted text into textbox
document.fm.textbox.value = bbcodetext;
// put the finsished text into finishedtext variable
finishedtext = document.fm.textbox.value;
} // end function convert()
</script>
<table style="background:pink;" cellspacing="10" width="100%"><tbody><tr><td>
</td><td valign="top">
<form name="fm">
<table border=0>
<tbody><tr><td align="left">
<input name="Convert" value="Chuyển định dạng" onclick="convert();" type="button">
<input name="back2html" value="Chuyển lại HTML" onclick="backtohtml();" type="button">
</td></tr>
<tr><td>
<br>
<input name="codetype" value="bbcode" checked="checked" onclick="showoptions();" type="radio">BBCode
<input name="codetype" value="vbcode" onclick="showoptions();" type="radio">vB Code
<input name="codetype" value="smf" onclick="showoptions();" type="radio">SMF Code
<input name="codetype" value="ipb" onclick="showoptions();" type="radio">IPB Code =>
<input name="test" type="text">
</td><td align="right">
</td></tr>
<tr><td><div id="vboption" style="visibility: hidden; position: absolute;">
<b>Chỉnh sửa:</b> nếu có <TEXTAREA> hoặc <SCRIPT> trong văn bản của bạn, bạn muốn đổi nó thành
<input name="option" value="code" type="radio">[code][/code]
<input name="option" value="html" type="radio">[html][/html]
<input name="option" value="php" checked="checked" type="radio">[php][/php]
</div><div id="ipboption" style="visibility: hidden; position: relative;">
<b>Chỉnh sửa:</b> nếu có <TEXTAREA> hoặc <SCRIPT> trong văn bản của bạn, bạn muốn đổi nó thành
<input name="option1" value="code" type="radio">[code][/code]
<input name="option1" value="html" type="radio">[html][/html]
<input name="option1" value="sql" checked="checked" type="radio">[sql][/sql]
</div>
</td></tr>
<tr><td>
<textarea name="textbox" cols="116" rows="15" onclick="this.select()">Mời bạn chèn văn bản HTML cần chuyển vào ô này ^^ - http://cafam.123.st
</textarea>
</td></tr>
</tbody></table>[/code]
Ồ không được thật, nhưng tại sao thì mình không biết
[code]<head>
<title>..:: C.A.F - Convert HTML ::..</title>
<link rel="shortcut icon" type="image/x-icon" href="http://mmstroe.summerhost.info/favicon.ico" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</head>
<script type="text/javascript" language="JavaScript">
function shrink(what)
{
IE = (document.all)
if (IE)
displaystyle = "block";
else
displaystyle = "table-cell";
var totalTDs = document.getElementsByTagName("TD").length;
var what2 = what + "shrink"; // change DIV for code
var what3 = what + "code"; // change TH for code
if (document.getElementById(what2).innerHTML == "[-]")
{
document.getElementById(what2).innerHTML = "[+]";
for(i=0; i < totalTDs; i++)
{
if (document.getElementsByTagName("TD")<i>.className == what)
{
http://document.getElementsByTagName("TD")[i].style.visibility='hidden';
document.getElementsByTagName("TD")[i].style.display='none';
}
}
http://document.getElementById("bbccol").width = "1";
http://document.getElementById("contable").width="50";
document.getElementById(what3).style.display="none";
}
else
{
document.getElementById(what2).innerHTML = "[-]";
for(i=0; i < totalTDs; i++)
{
if (document.getElementsByTagName("TD")[i].className == what)
{
http://document.getElementsByTagName("TD")[i].style.visibility='visible';
document.getElementsByTagName("TD")[i].style.display=displaystyle;
}
document.getElementById(what3).style.display=displaystyle;
}
}
http://document.getElementById("bbccol").width = "350";
} // end function shrink()
function ClipBoard()
{
Copied = document.fm.textbox.createTextRange();
Copied.execCommand("Copy");
document.fm.textbox.select();
} // end functuon ClipBoard()
function selectall()
{
document.fm.textbox.select();
} // end function selectall()
var htmltext; // variable to save the html data
var finishedtext; // the variable will hold the finished text
// so we know if we have to put textbox back
// to HTML before converting to another type
// pof code
function item(pos, font, face, size, color)
{
this.pos = pos;
this.font = font;
this.face = face;
this.size = size;
this.color = color;
}
fontlist = new item(50);
fontclose = new item(50);
anchorlist = new item(50);
textarealist = new item(20);
function do_font(fonttext)
{
var i = 0;
var j = 0;
var n;
var pos;
var subfonttext;
fonttext = fonttext.toUpperCase();
http://document.fm.textbox.value = fonttext;
for (pos = 0; pos != -1; pos)
{
pos = fonttext.indexOf("<FONT", pos);
http://document.fm.textbox.value = document.fm.textbox.value + pos;
if (pos != -1) // if <FONT is found
{
n = fonttext.indexOf(">", pos);
fontlist[i] = new item(0, 0, 0, 0, 0);
fontlist[i].pos = pos;
fontlist[i].font = 1;
subfonttext = fonttext.substring(pos, n);
if (subfonttext.search(/FACE/) != -1)
fontlist[i].face = 1;
else
fontlist[i].face = 0;
if (subfonttext.search(/SIZE/) != -1)
fontlist[i].size = 1;
else
fontlist[i].size = 0;
if (subfonttext.search(/COLOR/) != -1)
fontlist[i].color = 1;
else
fontlist[i].color = 0;
http://document.fm.textbox.value = document.fm.textbox.value + i +
//subfonttext + fontlist[i].font + fontlist[i].color + '.';
pos++;
i++;
} // end if <FONT is found
//i--; // so i equals the length of fontlist
} // end for
// Now find all closing font tags </FONT>
for (pos = 0; pos != -1; pos)
{
pos = fonttext.indexOf("</FONT>", pos++);
http://document.fm.textbox.value = document.fm.textbox.value + pos;
if (pos != -1) // if </FONT> found
{
http://document.fm.textbox.value = document.fm.textbox.value + "i=" + i + ".";
fontclose[j] = new item(0, 0, 0, 0, 0);
fontclose[j].pos = pos;
fontclose[j].font = 1;
for (ii = i-1; ii >= 0; ii--)
{
http://document.fm.textbox.value = document.fm.textbox.value + "h1.";
if (fontlist[ii].pos < pos)
{
http://document.fm.textbox.value = document.fm.textbox.value + "h2.";
if (fontlist[ii].font == 1)
{
http://document.fm.textbox.value = document.fm.textbox.value + "h3.";
fontlist[ii].font = 0;
fontclose[j].color = fontlist[ii].color;
fontclose[j].size = fontlist[ii].size;
fontclose[j].face = fontlist[ii].face;
ii = -1; // since we found it, exit for loop
} // end if opening FONT tag
} // end if
} // end for
pos++;
j++;
} // end if </FONT> found
else
{
fontclose[j] = new item(0, 0, 0, 0, 0);
fontclose[j].font = 0;
}
} // end for
//for (i = 0;fontclose[i].font != 0; i++)
// {
// document.fm.textbox.value = document.fm.textbox.value +
// fontclose[i].font + fontclose[i].color +
// fontclose[i].size + fontclose[i].face;
// }
//alert("hi");
} // end function do_font()
function do_anchor(fonttext)
{
var i = 0;
var j = 0;
var n;
var pos;
var subfonttext;
fonttext = fonttext.toUpperCase();
http://document.fm.textbox.value = fonttext;
for (pos = 0; pos != -1; pos)
{
pos = fonttext.indexOf("<A HREF", pos);
http://document.fm.textbox.value = document.fm.textbox.value + pos;
if (pos != -1) // if <A HREF is found
{
n = fonttext.indexOf(">", pos);
anchorlist[i] = new item(0, 0, 0, 0, 0);
//fontlist[i].pos = pos;
anchorlist[i].font = 1;
subfonttext = fonttext.substring(pos, n);
if (subfonttext.search(/MAILTO:/) != -1)
{
subfonttext = subfonttext.replace(/<A HREF=MAILTO:/, "");
subfonttext = subfonttext.replace(/\"/, "");
subfonttext = subfonttext.replace(/\'/, "");
anchorlist[i].pos = 1; // mailto: flag
subfonttext = subfonttext.toLowerCase();
anchorlist[i].face = subfonttext; // email address
}
else
{
anchorlist[i].pos = 2; // http: flag
}
http://document.fm.textbox.value = document.fm.textbox.value + i +
//subfonttext + fontlist[i].font + fontlist[i].color + '.';
pos++;
i++;
} // end if <A HREF is found
else
{
anchorlist[i] = new item(0, 0, 0, 0, 0);
anchorlist[i].pos = 0; // no more anchors flag
}
//i--; // so i equals the length of fontlist
} // end for
} // end function do_anchor()
// this function copies all the textarea data to strings
// to preserve its code exactly as it is and not change it
function do_textarea(fonttext)
{
var i = 0;
var j = 0;
var n;
var pos;
var subfonttext;
textareatext = fonttext; // need this to preserve case
fonttext = fonttext.toUpperCase();
http://document.fm.textbox.value = fonttext;
for (pos = 0; pos != -1; pos)
{
pos = fonttext.indexOf("<TEXTAREA", pos);
http://document.fm.textbox.value = document.fm.textbox.value + pos;
if (pos != -1) // if <TEXTAREA is found
{
n = fonttext.indexOf(">", pos);
pos = fonttext.indexOf("</TEXTAREA>", n);
if (pos != -1) // if </TEXTAREA> is found
{
textarealist[i] = new item(0, 0, 0, 0, 0);
textarealist[i].face = textareatext.substring(n+1, pos);
// notice that we copied the area from textareatext
// because it has not had its case changed to upper
//fontlist[i].pos = pos;
textarealist[i].pos = 1;
}
http://document.fm.textbox.value = document.fm.textbox.value + i +
//subfonttext + fontlist[i].font + fontlist[i].color + '.';
pos++;
i++;
} // end if <TEXTAREA is found
else
{
textarealist[i] = new item(0, 0, 0, 0, 0);
textarealist[i].pos = 0; // no more textareas flag
}
//i--; // so i equals the length of fontlist
} // end for
} // end function do_textarea()
function backtohtml()
{
document.fm.textbox.value = htmltext;
} // end function back2html()
function showoptions()
{
var codetype;
for (i = 0; i < 4; i++)
{
if (document.fm.codetype[i].checked)
codetype = document.fm.codetype[i].value;
}
document.getElementById('vboption').style.visibility = "hidden";
document.getElementById('ipboption').style.visibility = "hidden";
if (codetype == "vbcode")
document.getElementById('vboption').style.visibility = "visible";
else if (codetype == "ipb")
document.getElementById('ipboption').style.visibility = "visible";
} // end function showoptions()
function convert()
{
var bbcodetext = document.fm.textbox.value;
var codetype;
var vbcodeoption;
var ipbcodeoption;
for (i = 0; i < 4; i++)
{
if (document.fm.codetype[i].checked)
codetype = document.fm.codetype[i].value;
}
document.fm.test.value = codetype;
for (i = 0; i < 3; i++)
{
if (document.fm.option[i].checked)
vbcodeoption = document.fm.option[i].value;
}
for (i = 0; i < 3; i++)
{
if (document.fm.option1[i].checked)
ipbcodeoption = document.fm.option1[i].value;
}
// Check to see if current textbox is the same
// as what is stored in finishedtext. If so
// then revert back to HTML text
if (finishedtext == bbcodetext)
{
document.fm.textbox.value = htmltext;
bbcodetext = document.fm.textbox.value;
}
// copy the textbox.value into htmltext
htmltext = document.fm.textbox.value;
do_font(bbcodetext);
bbcodetext = bbcodetext.replace(/<SCRIPT[^>]*>/gi, "<TEXTAREA>");
bbcodetext = bbcodetext.replace(/<\/SCRIPT>/gi, "</TEXTAREA>");
do_textarea(bbcodetext);
// maybe they put spaces around the = . Remove them
bbcodetext = bbcodetext.replace(/ = /gi, "=");
// maybe they put quotes surrounding the value
// so look for =" and ">
bbcodetext = bbcodetext.replace(/=\"/gi, "=");
//bbcodetext = bbcodetext.replace(/\">/gi, ">");
// maybe they put single quote surrounding the value
// so look for =' and '>
bbcodetext = bbcodetext.replace(/=\'/gi, "=");
//bbcodetext = bbcodetext.replace(/\'>/gi, ">");
bbcodetext = bbcodetext.replace(/<param name=movie[^>]*value=/gi, "<movie=");
bbcodetext = bbcodetext.replace(/ BORDER=[^\'\">]*[\'\">]/gi, "");
//bbcodetext = bbcodetext.replace(/ BORDER=[^\'>]*\'/gi, " ");
bbcodetext = bbcodetext.replace(/ TARGET=[^\'\">]*[\'\">]/gi, "");
//bbcodetext = bbcodetext.replace(/ TARGET=[^\'>]*\'/gi, "");
bbcodetext = bbcodetext.replace(/ CLASSID=[^\'\">]*[\'\">]/gi, "");
//bbcodetext = bbcodetext.replace(/ CLASSID=[^\'>]*\'/gi, "");
bbcodetext = bbcodetext.replace(/ ID=[^\'\">]*[\'\">]/gi, "");
//bbcodetext = bbcodetext.replace(/ ID=[^\'>]*\'/gi, "");
bbcodetext = bbcodetext.replace(/ NAME=[^\'\">]*[\'\">]/gi, "");
//bbcodetext = bbcodetext.replace(/ NAME=[^\'>]*\'/gi, "");
//bbcodetext = bbcodetext.replace(/ ALIGN=[^\"]*\"/gi, "");
//bbcodetext = bbcodetext.replace(/ ALIGN=[^\']*\'/gi, "");
//bbcodetext = bbcodetext.replace(/ ALIGN=[^>]*>/gi, ">");
bbcodetext = bbcodetext.replace(/ STYLE=[^\'\">]*[\'\">]/gi, "");
//bbcodetext = bbcodetext.replace(/ STYLE=[^\'>]*\'/gi, "");
bbcodetext = bbcodetext.replace(/ CLASS=[^\'\">]*[\'\">]/gi, "");
//bbcodetext = bbcodetext.replace(/ CLASS=[^\'>]*\'/gi, "");
bbcodetext = bbcodetext.replace(/ ALT=[^\'\">]*[\'\">]/gi, "");
//bbcodetext = bbcodetext.replace(/ ALT=[^\'>]*\'/gi, "");
bbcodetext = bbcodetext.replace(/ TITLE=[^\'\">]*[\'\">]/gi, "");
do_anchor(bbcodetext);
http://document.fm.textbox.value = bbcodetext;
//alert('here');
bbcodetext = bbcodetext.replace(/<BR>/gi, "\r");
bbcodetext = bbcodetext.replace(/<BR \/>/gi, "\r");
bbcodetext = bbcodetext.replace(/<p>/gi, "\r\r");
bbcodetext = bbcodetext.replace(/<P [^>]*>/gi, "\r\r");
bbcodetext = bbcodetext.replace(/<CODE>/gi, "</span><table width="90%" cellspacing="1" cellpadding="0" border="0" align="center"><tr><td><span class="genmed"><b>Code:</b></span></td></tr><tr><td class="code"><div class="cont_code" curpos="0" maxpos="0" pageincrement="480" increment="10" collapsed="true">");
bbcodetext = bbcodetext.replace(/<\/CODE>/gi, "</div></td></tr></table><span class="postbody">");
bbcodetext = bbcodetext.replace(/<BLOCKQUOTE>/gi, "</span><table width="90%" cellspacing="1" cellpadding="0" border="0" align="center"><tr><td><span class="genmed"><b>Trích dẫn:</b></span></td></tr><tr><td class="quote">");
bbcodetext = bbcodetext.replace(/<\/BLOCKQUOTE>/gi, "</td></tr></table><span class="postbody">");
bbcodetext = bbcodetext.replace(/<UL[^>]*>/gi, "<ul>");
bbcodetext = bbcodetext.replace(/<\/UL>/gi, "</ul>");
bbcodetext = bbcodetext.replace(/<OL[^>]*>/gi, "<ol type="1">");
bbcodetext = bbcodetext.replace(/<\/OL>/gi, "</ol>");
bbcodetext = bbcodetext.replace(/<LI>/gi, "[*]");
//bbcodetext = bbcodetext.replace(/<A HREF=mailto:/gi, "");
//bbcodetext = bbcodetext.replace(/<A HREF/gi, "[url");
//bbcodetext = bbcodetext.replace(/<\/A>/gi, "[/url]");
// *** Jeff!! These two remarked statements are the solution
// to make a better converter:
// (.*?) = match any character except new line 0 or more times and remember the match
// ([\s\S]*?) = match \s any white space char once inclduing \n, \S match any non-white space char, *? any number of times or 0 times
//bbcodetext = bbcodetext.replace(/<A[\s\S]*?HREF=\"(.*?)\"[\s\S]*?>([\s\S]*?)<\/A>/gi, "[url=$1]$2[\/url]");
bbcodetext = bbcodetext.replace(/<IMG[\s\S]*?SRC=([\s\S]*?)\"[\s\S]*?>/gi, "[img]$1[\/img]");
bbcodetext = bbcodetext.replace(/<IMG[\s\S]*?SRC=([\s\S]*?)'[\s\S]*?>/gi, "[img]$1[\/img]");
//bbcodetext = bbcodetext.replace(/<IMG SRC=/gi, "[img]");
//bbcodetext = bbcodetext.replace(/.jpg[^>]*>/gi, ".jpg[/img]");
//bbcodetext = bbcodetext.replace(/.gif[^>]*>/gi, ".gif[/img]");
//bbcodetext = bbcodetext.replace(/.bmp[^>]*>/gi, ".bmp[/img]");
//bbcodetext = bbcodetext.replace(/.png[^>]*>/gi, ".png[/img]");
bbcodetext = bbcodetext.replace(/<BIG>/gi, "<strong>");
bbcodetext = bbcodetext.replace(/<\/BIG>/gi, "</strong>");
bbcodetext = bbcodetext.replace(/<B>/gi, "<strong>");
bbcodetext = bbcodetext.replace(/<\/B>/gi, "</strong>");
bbcodetext = bbcodetext.replace(/<U>/gi, "<u>");
bbcodetext = bbcodetext.replace(/<\/U>/gi, "</u>");
bbcodetext = bbcodetext.replace(/<I>/gi, "[i]");
bbcodetext = bbcodetext.replace(/<\/I>/gi, "</i>");
if (codetype == "bbcode")
{
bbcodetext = bbcodetext.replace(/<FONT Face[^\'\">]*[\'\">]/gi, "<FONT");
//bbcodetext = bbcodetext.replace(/<FONT Face[^\']*\'/gi, "<FONT");
//bbcodetext = bbcodetext.replace(/<FONT Face[^ ]* /gi, "<FONT ");
//bbcodetext = bbcodetext.replace(/ FACE=[^ ]*\ /gi, " ");
//bbcodetext = bbcodetext.replace(/ FACE=[^>]*>/gi, ">");
bbcodetext = bbcodetext.replace(/ FACE=[^\'\"]*[\'\"]/gi, "");
//bbcodetext = bbcodetext.replace(/ FACE=[^\']*\'/gi, ">");
//alert(bbcodetext);
//bbcodetext = bbcodetext.replace(/<\/FONT>/gi, "[/size][/color]");
} // end if bbcode
if (codetype == "vbcode")
{
bbcodetext = bbcodetext.replace(/<STRONG>/gi, "[highlight]");
bbcodetext = bbcodetext.replace(/<\/STRONG>/gi, "[/highlight]");
bbcodetext = bbcodetext.replace(/<TEXTAREA[^>]*>/gi, "[code1]");
bbcodetext = bbcodetext.replace(/<\/TEXTAREA>/gi, "[/code1]");
// <FONT STYLE="background-color:yellow> <-- for hightlighting
} // end if vbcode
if (codetype == "ipb")
{
bbcodetext = bbcodetext.replace(/<STRIKE>/gi, "[s]");
bbcodetext = bbcodetext.replace(/<\/STRIKE>/gi, "[/s]");
bbcodetext = bbcodetext.replace(/<TEXTAREA[^>]*>/gi, "[code3]");
bbcodetext = bbcodetext.replace(/<\/TEXTAREA>/gi, "[/code3]");
// <FONT STYLE="background-color:yellow> <-- for hightlighting
} // end if ipb
if (codetype == "bbcode" || codetype == "vbcode" ||
codetype == "ipb")
{
bbcodetext = bbcodetext.replace(/<PRE[^>]*>/gi, "</span><table width="90%" cellspacing="1" cellpadding="0" border="0" align="center"><tr><td><span class="genmed"><b>Code:</b></span></td></tr><tr><td class="code"><div class="cont_code" curpos="0" maxpos="0" pageincrement="480" increment="10" collapsed="true">");
bbcodetext = bbcodetext.replace(/<\/PRE>/gi, "</div></td></tr></table><span class="postbody">");
} // end if bbcode or vbcode
if (codetype == "bbcode" || codetype == "smf")
{
bbcodetext = bbcodetext.replace(/<TEXTAREA[^>]*>/gi, "[code2]");
bbcodetext = bbcodetext.replace(/<\/TEXTAREA>/gi, "[/code2]");
}
if (codetype == "smf" || codetype == "vbcode" ||
codetype == "ipb")
{
bbcodetext = bbcodetext.replace(/<FONT Face/gi, "[font");
bbcodetext = bbcodetext.replace(/ Face=/gi, "]<font face="");
//bbcodetext = bbcodetext.replace(/<\/FONT>/gi, "[/font">[/size][/color]");
bbcodetext = bbcodetext.replace(/<LEFT>/gi, "<div align="left">");
bbcodetext = bbcodetext.replace(/<\/LEFT>/gi, "</div>");
bbcodetext = bbcodetext.replace(/<CENTER>/gi, "<div style="margin:auto;text-align:center;width:100%">");
bbcodetext = bbcodetext.replace(/<\/CENTER>/gi, "</div>");
bbcodetext = bbcodetext.replace(/<RIGHT>/gi, "<div align="right">");
bbcodetext = bbcodetext.replace(/<\/RIGHT>/gi, "</div>");
} // end if smf or vbcode
if (codetype == "ipb" || codetype == "bbcode")
{
bbcodetext = bbcodetext.replace(/<STRONG>/gi, "<strong>");
bbcodetext = bbcodetext.replace(/<\/STRONG>/gi, "</strong>");
}
if (codetype == "smf")
{
// because smf does not have ordered list <OL> support
bbcodetext = bbcodetext.replace(/\[list=1\]/gi, "[list]");
bbcodetext = bbcodetext.replace(/<STRONG>/gi, "[glow=red,2,50]");
bbcodetext = bbcodetext.replace(/<\/STRONG>/gi, "[/glow]");
bbcodetext = bbcodetext.replace(/<STRIKE>/gi, "[s]");
bbcodetext = bbcodetext.replace(/<\/STRIKE>/gi, "[/s]");
bbcodetext = bbcodetext.replace(/<MARQUEE[^>]*>/gi, "[move]");
bbcodetext = bbcodetext.replace(/<\/MARQUEE>/gi, "[/move]");
bbcodetext = bbcodetext.replace(/<PRE>/gi, "[pre]");
bbcodetext = bbcodetext.replace(/<\/PRE>/gi, "[/pre]");
bbcodetext = bbcodetext.replace(/<HR[^>]*>/gi, "<hr />");
bbcodetext = bbcodetext.replace(/<object[^>]*width=/gi, "[flash=");
bbcodetext = bbcodetext.replace(/<object[^>]*height=/gi, "[flash=");
bbcodetext = bbcodetext.replace(/\" height=/gi, ",");
bbcodetext = bbcodetext.replace(/\' height=/gi, ",");
bbcodetext = bbcodetext.replace(/\" width=/gi, ",");
bbcodetext = bbcodetext.replace(/\' width=/gi, ",");
bbcodetext = bbcodetext.replace(/ width=/gi, ",");
bbcodetext = bbcodetext.replace(/ height=/gi, ",");
bbcodetext = bbcodetext.replace(/\<movie=/gi, "");
//bbcodetext = bbcodetext.replace(/<embed src=/gi, "");
bbcodetext = bbcodetext.replace(/.swf[^>]*>/gi, ".swf[/flash]");
bbcodetext = bbcodetext.replace(/<TABLE[^>]*>/gi, "<table>"); bbcodetext = bbcodetext.replace(/<TR[^>]*>/gi, "[tr]"); bbcodetext = bbcodetext.replace(/<TD[^>]*>/gi, "[td]"); bbcodetext = bbcodetext.replace(/<TH[^>]*>/gi, "[td]"); bbcodetext = bbcodetext.replace(/<\/TABLE>/gi, "</table>");
bbcodetext = bbcodetext.replace(/<\/TR>/gi, "[/tr]");
bbcodetext = bbcodetext.replace(/<\/TD>/gi, "[/td]");
bbcodetext = bbcodetext.replace(/<\/TH>/gi, "[/td]");
bbcodetext = bbcodetext.replace(/<SUP>/gi, "<sup>");
bbcodetext = bbcodetext.replace(/<\/SUP>/gi, "</sup>");
bbcodetext = bbcodetext.replace(/<SUB>/gi, "<sub>");
bbcodetext = bbcodetext.replace(/<\/SUB>/gi, "</sub>");
bbcodetext = bbcodetext.replace(/<TT>/gi, "[tt]");
bbcodetext = bbcodetext.replace(/<\/TT>/gi, "[/tt]");
bbcodetext = bbcodetext.replace(/<ABBR TITLE=/gi, "[acronym=");
bbcodetext = bbcodetext.replace(/<\/ABBR>/gi, "[/acronym]");
bbcodetext = bbcodetext.replace(/<ACRONYM TITLE=/gi, "[acronym=");
bbcodetext = bbcodetext.replace(/<\/ACRONYM>/gi, "[/acronym]");
} // end if smf
else
{
// table tags for everyone but smf
bbcodetext = bbcodetext.replace(/<TR[^>]*>/gi, "\r");
bbcodetext = bbcodetext.replace(/<TD[^>]*>/gi, " ");
bbcodetext = bbcodetext.replace(/<TH[^>]*>/gi, " ");
bbcodetext = bbcodetext.replace(/<\/TR>/gi, " ");
bbcodetext = bbcodetext.replace(/<\/TD>/gi, " ");
bbcodetext = bbcodetext.replace(/<\/TH>/gi, " ");
}
// font size and color tags
bbcodetext = bbcodetext.replace(/<FONT SIZE=/gi, "[size=");
bbcodetext = bbcodetext.replace(/<FONT color=/gi, "[color=");
// maybe they put the size and color in one font statement
// so look for SPACE color and SPACE size
bbcodetext = bbcodetext.replace(/ color=/gi, "][color=");
bbcodetext = bbcodetext.replace(/ size=/gi, "][size=");
// The following for loop is for /FONT tags
// we are removing global search because we have to remove
// each </FONT> tag one at a time because some are closing
// [color], [size], or [font]
var fonttag;
for (i = 0; fontclose[i].font != 0; i++)
{
fonttag = "";
if (codetype == "smf" || codetype == "vbcode" ||
codetype == "ipb")
if (fontclose[i].face == 1)
fonttag = "</font>";
if (fontclose[i].color == 1)
fonttag = fonttag + "</font>";
if (fontclose[i].size == 1)
fonttag = fonttag + "[/size]";
bbcodetext = bbcodetext.replace(/<\/FONT>/i, fonttag);
} // end for
// The following for loop is to search anchor tags
// to have the right closing for mailto or http.
// It also does </A> tags
// we remove the global case in the replace function
for (i = 0; anchorlist[i].pos != 0; i++)
{
if (anchorlist[i].pos == 2) // if URL
{
bbcodetext = bbcodetext.replace(/<A HREF/i, "[url");
bbcodetext = bbcodetext.replace(/<\/A>/i, "[/url]");
} // end if URL
if (anchorlist[i].pos == 1) // if mailto:
{
if (codetype == "bbcode")
bbcodetext = bbcodetext.replace(/<A HREF[^<]*<\/A>/i, anchorlist[i].face);
else // if codetype is smf or vbcode
{
bbcodetext = bbcodetext.replace(/<A HREF=MAILTO:/i, "[email=");
bbcodetext = bbcodetext.replace(/<\/A>/i, "[/email]");
}
} // end if mailto:
} // end for loop for anchor tags
// This replaces all remaining HTML code between < and >
//bbcodetext = htmltext.replace(/<[^>]*>/g, "");
bbcodetext = bbcodetext.replace(/<[^>]*>/g, "");
// This will convert all > into ] because we left
// some open up top such as removing <font size
// and <UL
bbcodetext = bbcodetext.replace(/>/g, "]");
bbcodetext = bbcodetext.replace(/\'>/g, "]");
bbcodetext = bbcodetext.replace(/\">/g, "]");
bbcodetext = bbcodetext.replace(/\']/g, "]");
bbcodetext = bbcodetext.replace(/\"]/g, "]");
// The following for loop searches through all textareas.
// It takes place after all < > tags have been removed
// because it needs to go back in and put all the data
// back into the <TEXTAREA></TEXTAREA> tags unchanged.
// For that we search for [code1] & [code2]
for (i = 0; textarealist[i].pos != 0; i++)
{
if (textarealist[i].pos == 1) // if TEXTAREA
{
//alert("hi");
// turn textarea to Vb Codes [php] tag
if (vbcodeoption == "php")
bbcodetext = bbcodetext.replace(/\[code1\][\w\W]*?\[\/code1\]/i, "[php]" + textarealist[i].face + "[/php]");
if (vbcodeoption == "code")
bbcodetext = bbcodetext.replace(/\[code1\][\w\W]*?\[\/code1\]/i, "</span><table width="90%" cellspacing="1" cellpadding="0" border="0" align="center"><tr><td><span class="genmed"><b>Code:</b></span></td></tr><tr><td class="code"><div class="cont_code" curpos="0" maxpos="0" pageincrement="480" increment="10" collapsed="true">" + textarealist[i].face + "</div></td></tr></table><span class="postbody">");
if (vbcodeoption == "html")
bbcodetext = bbcodetext.replace(/\[code1\][\w\W]*?\[\/code1\]/i, "[html]" + textarealist[i].face + "[/html]");
if (ipbcodeoption == "sql")
bbcodetext = bbcodetext.replace(/\[code3\][\w\W]*?\[\/code3\]/i, "[sql]" + textarealist[i].face + "[/sql]");
if (ipbcodeoption == "code")
bbcodetext = bbcodetext.replace(/\[code3\][\w\W]*?\[\/code3\]/i, "</span><table width="90%" cellspacing="1" cellpadding="0" border="0" align="center"><tr><td><span class="genmed"><b>Code:</b></span></td></tr><tr><td class="code"><div class="cont_code" curpos="0" maxpos="0" pageincrement="480" increment="10" collapsed="true">" + textarealist[i].face + "</div></td></tr></table><span class="postbody">");
if (ipbcodeoption == "html")
bbcodetext = bbcodetext.replace(/\[code3\][\w\W]*?\[\/code3\]/i, "[html]" + textarealist[i].face + "[/html]");
// turn textarea to bbcode & smf [code] tag
bbcodetext = bbcodetext.replace(/\[code2\][\w\W]*?\[\/code2\]/i, "[code]" + textarealist[i].face + "[/code]");
} // end if TEXTAREA
} // end for loop for textarea tags
// put converted text into textbox
document.fm.textbox.value = bbcodetext;
// put the finsished text into finishedtext variable
finishedtext = document.fm.textbox.value;
} // end function convert()
</script>
<table style="background:pink;" cellspacing="10" width="100%"><tbody><tr><td>
</td><td valign="top">
<form name="fm">
<table border=0>
<tbody><tr><td align="left">
<input name="Convert" value="Chuyển định dạng" onclick="convert();" type="button">
<input name="back2html" value="Chuyển lại HTML" onclick="backtohtml();" type="button">
</td></tr>
<tr><td>
<br>
<input name="codetype" value="bbcode" checked="checked" onclick="showoptions();" type="radio">BBCode
<input name="codetype" value="vbcode" onclick="showoptions();" type="radio">vB Code
<input name="codetype" value="smf" onclick="showoptions();" type="radio">SMF Code
<input name="codetype" value="ipb" onclick="showoptions();" type="radio">IPB Code =>
<input name="test" type="text">
</td><td align="right">
</td></tr>
<tr><td><div id="vboption" style="visibility: hidden; position: absolute;">
<b>Chỉnh sửa:</b> nếu có <TEXTAREA> hoặc <SCRIPT> trong văn bản của bạn, bạn muốn đổi nó thành
<input name="option" value="code" type="radio">[code][/code]
<input name="option" value="html" type="radio">[html][/html]
<input name="option" value="php" checked="checked" type="radio">[php][/php]
</div><div id="ipboption" style="visibility: hidden; position: relative;">
<b>Chỉnh sửa:</b> nếu có <TEXTAREA> hoặc <SCRIPT> trong văn bản của bạn, bạn muốn đổi nó thành
<input name="option1" value="code" type="radio">[code][/code]
<input name="option1" value="html" type="radio">[html][/html]
<input name="option1" value="sql" checked="checked" type="radio">[sql][/sql]
</div>
</td></tr>
<tr><td>
<textarea name="textbox" cols="116" rows="15" onclick="this.select()">Mời bạn chèn văn bản HTML cần chuyển vào ô này ^^ - http://cafam.123.st
</textarea>
</td></tr>
</tbody></table>[/code]
Ồ không được thật, nhưng tại sao thì mình không biết
Re: [Share code] Trang tiện ích Convert HTML => BBCode
Nguyên nhân có lẽ nằm ở
Hoặc là do code dài quá, thử ngắt khúc ra thì vẫn được.
- Code:
bbcodetext = bbcodetext.replace(/\[code2\][\w\W]*?\[\/code2\]/i, "[code]" + textarealist[i].face + "[/code]");
Hoặc là do code dài quá, thử ngắt khúc ra thì vẫn được.
Re: [Share code] Trang tiện ích Convert HTML => BBCode
Anh EA nói đúng rồi đó ! Trong code này phần JS có tag [CODE] rồi nên bỏ vào thẻ không được đâu !
Mình đã save file này trên Tinypaste rồi ! Các bạn vào đây để lấy nhé ^^
[code]http://tinypaste.com/b78ee9[/code]
OK ^^
Mình đã save file này trên Tinypaste rồi ! Các bạn vào đây để lấy nhé ^^
[code]http://tinypaste.com/b78ee9[/code]
OK ^^
Re: [Share code] Trang tiện ích Convert HTML => BBCode
kô được bạn ơi, bấm đi bấm lại, vẫn kô thấy được bạn fix lại 1 code hoàn chỉnh đi
Similar topics
» [Share] Code trang chuyển từ html sang bbcode
» share html trang chu
» share 2 Trang HTML mới kiếm được
» Cho mình xin code hiện trang html ra trang index[✔]
» code chat ola chen vao trang html
» share html trang chu
» share 2 Trang HTML mới kiếm được
» Cho mình xin code hiện trang html ra trang index[✔]
» code chat ola chen vao trang html
Trang 1 trong tổng số 1 trang
Permissions in this forum:
Bạn không có quyền trả lời bài viết