一聚教程网:一个值得你收藏的教程网站

热门教程

HTML与UBB代码互相转换

时间:2022-07-02 14:12:05 编辑:袖梨 来源:一聚教程网

提示:您可以先修改部分代码再运行
');////////// str = str.replace(/[hr]/ig,'
'); str = str.replace(/[/(size|color|font|backcolor)]/ig,''); str = str.replace(/[(sub|sup|u|i|strike|b|blockquote|li)]/ig,'<$1>'); str = str.replace(/[/(sub|sup|u|i|strike|b|blockquote|li)]/ig,''); str = str.replace(/[/align]/ig,'

'); str = str.replace(/[(/)?h([1-6])]/ig,'<$1h$2>'); str = str.replace(/[align=(left|center|right|justify)]/ig,'

'); str = str.replace(/[size=(d+?)]/ig,''); str = str.replace(/[color=([^[<]+?)]/ig, ''); str = str.replace(/[backcolor=([^[<]+?)]/ig, ''); str = str.replace(/[font=([^[<]+?)]/ig, ''); str = str.replace(/[list=(a|A|1)](.+?)[/list]/ig,'

    $2
'); str = str.replace(/[(/)?list]/ig,'<$1ul>'); str = str.replace(/[em:(d+)]/ig, ''); str = str.replace(/[img=(d+),(d+),(.+)]s*(S+)[/img]/ig,''));str = str.replace(/[img=(d+),(d+)]s*(S+)[/img]/ig,''));str = str.replace(/[img=(d+),(d+)]s*(S+)[/img]/ig,''); str = str.replace(/[img]([^[]*)[/img]/ig,''); //////////////////////// //str = str.replace(/[flash=(d+),(d+)]s*(S+)[/flash]/ig,'')); //str = str.replace(/[flash]([^[]*)[/flash]/ig,''); str = str.replace(/[flash].[^[]*(.swf)[/flash]/ig,'点击开新窗口欣赏该flash动画![全屏欣赏]
$2
'); str = str.replace(/[flash=*([0-9]*),*([0-9]*)]).[^[]*(.swf)[/flash]/ig,'点击开新窗口欣赏该flash动画![全屏欣赏]
$4
'); str = str.replace(/[wmv](.[^[]*)[/wmv]/ig,''); str = str.replace(/[wmv=*([0-9]*),*([0-9]*)](.[^[]*)[/wmv]/ig,''); str = str.replace(/[rm](.[^[]*)[/rm]/ig,'
'); str = str.replace(/[rm=*([0-9]*),*([0-9]*)](.[^[]*)[/rm]/ig,'
'); str = str.replace(/[url=([^]]+)]([^[]+)[/url]/ig, ''+'$2'+''); str = str.replace(/[url]([^[]+)[/url]/ig, ''+'$1'+''); str = str.replace(/[email=(.[^[]*)](.*?)[/email]/ig, '$2'); str = str.replace(/[email])(.*?)([/email]/ig,'$2'); str = str.replace(/[table=(.[^[]*)]/ig,''); str = str.replace(/[td=([0-9]*),([0-9]*),([0-9]*)]/ig,'
'); var re = /s*[table(=(d{1,3}%?))?][nr]*([sS]+?)[nr]*[/table]s*/ig; str = str.replace(re, function($1, $2, $3, $4) {return parsetable($3, $4);}); str = str.replace(re, function($1, $2, $3, $4) {return parsetable($3, $4);}); str = str.replace(re, function($1, $2, $3, $4) {return parsetable($3, $4);}); str = str.replace(re, function($1, $2, $3, $4) {return parsetable($3, $4);}); return str; } function code(str){ var string = '

 提示:您可以先修改部分代码再运行
'; return string; } function quote(str){ var string = '
'+str+'
'; return string; } function parsetable(width, str){ if(typeof width == 'undefined'){ var width = ''; }else{ width = width.substr(width.length - 1, width.length) == '%' ? (width.substr(0, width.length - 1) <= 98 ? width : '98%') : (width <= 560 ? width : '98%'); } var string = ''; str = str.replace(/[td=(d{1,2}),(d{1,2})(,(d{1,3}%?))?]/ig, ''); str = str.replace(/[td]/ig, ''); str = str.replace(/[/tr]/ig, ''); string += str; string += '
'); str = str.replace(/[tr]/ig, '
'); str = str.replace(/[/td]/ig, '
'; return string; } function tabletag(attributes){ var ; re = /']?)(d{1,3}%?)(1)/ig; var matches = re.exec(attributes); if(matches != null && matches.length) { %' ? (matches[2].substr(0, matches[2].length - 1) <= 98 ? matches[2] : '98%') : (matches[2] <= 560 ? matches[2] : '98%'); }else{ re = /widths?:s?(d{1,3})([px|%])/ig; var matches = re.exec(attributes); if(matches != null && matches.length) { %' ? (matches[1] <= 98 ? matches[1] : '98%') : (matches[1] <= 560 ? matches[1] : '98%'); } } return ' ? '[table]' : '[table=' + width + ']'; } function tdtag(attributes){ var colspan = 1; var rowspan = 1; var ; re = /colspan=(["']?)(d{1,2})(1)/ig; var matches = re.exec(attributes); if(matches != null){ colspan = matches[2]; } re = /rowspan=(["']?)(d{1,2})(1)/ig; var matches = re.exec(attributes); if(matches != null){ rowspan = matches[2]; } re = /']?)(d{1,3}%?)(1)/ig; var matches = re.exec(attributes); if(matches != null){ width = matches[2]; } return in_array(width, ['', '0', '100%']) ? (colspan == 1 && rowspan == 1 ? '[td]' : '[td=' + colspan + ',' + rowspan + ']') : '[td=' + colspan + ',' + rowspan + ',' + width + ']'; } function runCode(obj) { var winname = window.open('', "_blank", ''); winname.document.open('text/html', 'replace'); winname.opener = null // 防止代码对页面修改 winname.document.write(obj.value); winname.document.close(); } function saveCode(obj) { var winname = window.open('', '_blank', 'top=10000'); winname.document.open('text/html', 'replace'); winname.document.write(obj.value); winname.document.execCommand('saveas','','code.htm'); winname.close(); } function HTMLtoUBB(){ var str = pattern(document.getElementById("htmlsource").value); document.getElementById("ubbresult").value=str; } function UBBtoHTML(){ var str = up(document.getElementById("ubbcode").value); document.getElementById("htmlcode").value=str; }
请输入Html代码,转换为UBB:



  

对应UBB代码为:

请输入UBB,转换为Html:



  

对应Html代码为:

提示:您可以先修改部分代码再运行