HTML and UBB code conversion

Source: Internet
Author: User
Tip: you can modify some code before running

<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>HTML and UBB code conversion</title><script language="javascript">Function pattern (str) {// str = str. replace (/(\ r \ n | \ r)/ig, ''); str = str. replace (/<br[^>] *>/Ig, '\ n'); str = str. replace (/<p[^>\/] * \/>/Ig, '\ n'); str = str. replace (/\ son [\ w] {3, 16} \ s? = \ S * ([\ '\ "]). +? \ 1/ig, ''); str = str. replace (/<hr[^>] *>/Ig, '[hr]'); str = str. replace (/<(sub | sup | u | strike | B | I | pre)>/ig, '[$1]'); str = str. replace (/<\/(sub | sup | u | strike | B | I | pre)>/ig, '[/$1]'); str = str. replace (/<(\/)? Strong>/ig, '[$ 1b]'); str = str. replace (/<(\/)? Em>/ig, '[$ 1i]'); str = str. replace (/<(\/)? Blockquote ([^>] *)>/ig, '[$1 blockquote]'); str = str. replace (// ig, "[em \: $1]"); str = str. replace (//, '[img = $2, $3, $4] $1 [/img]'); str = str. replace (/] * src = [\ '\ "\ s] * ([^ \ s \' \"] +) [^>] *>/ig, '[img]' + '$ 1' +' [/img] '); // str = str. replace (//, '[flash = $2, $3] $1 [/flash]'); str = str. replace (// ig, "[flash] $1 [/flash]"); // str = str. replace (/<object.+?width=\"(\d+)\"\s*height=\"(\d+)\".+?value=\"(.+?\.)(rm|swf).+<\/object>/ig, "[$4=$1,$2]$3$4[/$4]");str = str.replace(/<a[^>]*href=[\'\"\s]*([^\s\'\"]*)[^>]*>(.+?)<\/a>/ig,'[url=$1]'+'$2'+'[/url]');//str = str.replace(/<h([1-6]+)([^>]*)>(.*?)<\/h\1>/ig,function($1,$2,$3,$4){return h($3,$4,$2);});str = str.replace(/<table([^>]*width[^>]*)>/ig, function($1, $2) {return tabletag($2);});str = str.replace(/<table[^>]*>/ig, '[table]');str = str.replace(/<tr[^>]*>/ig, '[tr]');str = str.replace(/<td>/ig, '[td]');str = str.replace(/<td([^>]+)>/ig, function($1, $2) {return tdtag($2);});str = str.replace(/<\/td>/ig, '[/td]');str = str.replace(/<\/tr>/ig, '[/tr]');str = str.replace(/<\/table>/ig, '[/table]');str = str.replace(/<[^>]*?>/ig, '');str = str.replace(/&/ig, '&');str = str.replace(/</ig, '<');str = str.replace(/>/ig, '>');return str;}function up(str){str = str.replace(/</ig,'<');str = str.replace(/>/ig,'>');str = str.replace(/\n/ig,'<br />');str = str.replace(/\[code\](.+?)\[\/code\]/ig, function($1, $2) {return code($2);});/////str = str.replace(/\[html\]([^\[]*)\[\/html\]/ig,'<textarea name ="textarea" >$1');//////////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\]([^\[]*)\[\/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,'[全屏欣赏]
$2');str = str.replace(/\[flash=*([0-9]*),*([0-9]*)\]).[^\[]*(.swf)\[\/flash\]/ig,'[全屏欣赏]
$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}%?))?\][\n\r]*([\s\S]+?)[\n\r]*\[\/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 = '
'+str+'
 提示:您可以先修改部分代码再运行
';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 width = '';re = /width=(["']?)(\d{1,3}%?)(\1)/ig;var matches = re.exec(attributes);if(matches != null && matches.length) {width = matches[2].substr(matches[2].length - 1, matches[2].length) == '%' ?(matches[2].substr(0, matches[2].length - 1) <= 98 ? matches[2] : '98%') :(matches[2] <= 560 ? matches[2] : '98%');}else{re = /width\s?:\s?(\d{1,3})([px|%])/ig;var matches = re.exec(attributes);if(matches != null && matches.length) {width = matches[2] == '%' ? (matches[1] <= 98 ? matches[1] : '98%') : (matches[1] <= 560 ? matches[1] : '98%');}}return width == '' ? '[table]' : '[table=' + width + ']';}function tdtag(attributes){var colspan = 1;var rowspan = 1;var width = '';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 = /width=(["']?)(\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代码为:

请输入UBB,转换为Html:



点击转换为Html   清空结果

对应Html代码为:


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.