UBB代码对于经常上论坛的朋友来说是最熟悉不过了。
经典论坛的UBB转换我觉得是处理的非常好的,研究了一下它的转换结果[因为没有源码:)],做了下面的演示。转换结果基本上觉得象了。
主要是针对
<script>
strIcons = "1" //允许笑脸转换
strSmile="1" //同上
ImgName="em"
picurl="pic/"
function UBBCode(content,html){
st=new Date().getTime()
content=content.replace(/\[(\/)?phx_code\]/ig,"{$1phx_code}");
content=content.replace(/\[(\/)?phx_html\]/ig,"{$1phx_html}");
content="[phx_code]" content "[/phx_code]";
content=content.replace(/(\[code\]([\s\S] ?)\[\/code\])/ig,"[/phx_code]$1[phx_code]");
content=content.replace(/\[phx_code\]([\s\S]*?)\[\/phx_code\]/ig,function($1,$2){if(html=="html"){return(HTMLCode($2));}else{return(trans($2));}});
content=content.replace(/\[code\](\r\n)?([\s\S] ?)\[\/code\]/ig,function($1,$2,$3){return("<PRE class=CodeSamp>" DvbbsHtmlAn($3) "</PRE>")});
content=content.replace(/\{(\/)?phx_code\}/ig,"[$1phx_code]");
content=content.replace(/\{(\/)?phx_html\}/ig,"[$1phx_html]");
alert('共耗时 ' eval(new Date().getTime()-st) ' ms');
return(content);
}
function HTMLCode(content){
content="[phx_html]" content "[/phx_html]";
content=content.replace(/(\[html\]([\s\S] ?)\[\/html\])/ig,"[/phx_html]$1[phx_html]");
content=content.replace(/\[phx_html\]([\s\S]*?)\[\/phx_html\]/ig,function($1,$2){return(trans($2))});
content=content.replace(/\[html\]([\s\S] ?)\[\/html\]/ig,function($1,$2){return("<span><TEXTAREA cols=95 rows=12>" hencode($2) "</TEXTAREA><br><INPUT onclick=runCode() type=button value=运行代码>[Ctrl A 全部选择 提示:你可先修改部分代码,再按运行]</span>")});
return(content);
}
function hencode(fString){ //简单模拟server.htmlencode ASP中不用这个
fString = fString.replace(/&/ig,"&")
fString = fString.replace(/>/ig,">") //>
fString = fString.replace(/</ig,"<") //<
return fString;
}
function DvbbsHtmlAn(fString){
if(fString=="")return("");
fString=hencode(fString)
fString = fString.replace(/\t/ig," ") //Tab
fString = fString.replace(/"/ig,""") //"
fString = fString.replace(/'/ig,"'") //'
fString = fString.replace(/\r/ig,"") //回车是一个13 10
fString = fString.replace(/\n\n/ig,"<P>") //
fString = fString.replace(/\n/ig,"<BR>") //换行
欢迎光临 江西广告网 (http://bbs.jxadw.com/) | Powered by Discuz! X3.2 |