ubb.min.js 9.6 KB

1234567891011121314151617181920
  1. function ubb2html(g){function o(a){return a!=null&&a!=""?!isNaN(a):false}var b=String(g),m=[],n=0,s=["10px","13px","16px","18px","24px","32px","48px"];b=b.replace(/[<>&"]/g,function(a){return{"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;"}[a]});b=b.replace(/\r?\n/g,"<br />");b=b.replace(/\[code\s*(?:=\s*([^\]]+?))?\]([\s\S]*?)\[\/code\]/ig,function(a){n++;m[n]=a;return"[\tubbcodeplace_"+n+"\t]"});b=b.replace(/\[(\/?)(b|u|i|s|sup|sub)\]/ig,"<$1$2>");b=b.replace(/\[color\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/ig,
  2. '<font color="$1">');b=b.replace(/\[font\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/ig,'<font face="$1">');b=b.replace(/\[\/(color|font)\]/ig,"</font>");b=b.replace(/\[size\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/ig,function(a,h){if(h.match(/^\d+$/))h=s[h-1];return'<span style="font-size:'+h+';">'});b=b.replace(/\[back\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/ig,'<span style="background-color:$1;">');b=b.replace(/\[\/(size|back)\]/ig,"</span>");for(g=0;g<3;g++)b=b.replace(/\[align\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\](((?!\[align(?:\s+[^\]]+)?\])[\s\S])*?)\[\/align\]/ig,
  3. '<p align="$1">$2</p>');b=b.replace(/\[img\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/img\]/ig,'<img src="$1" alt="" />');b=b.replace(/\[img\s*=([^,\]]*)(?:\s*,\s*(\d*%?)\s*,\s*(\d*%?)\s*)?(?:,?\s*(\w+))?\s*\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*)?\s*\[\/img\]/ig,function(a,h,i,l,e,c){a='<img src="'+c+'" alt="'+h+'"';e=e?e:!o(i)?i:"";if(o(i))a+=' width="'+i+'"';if(o(l))a+=' height="'+l+'"';if(e)a+=' align="'+e+'"';a+=" />";return a});b=b.replace(/\[emot\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\/\]/ig,'<img emot="$1" />');
  4. b=b.replace(/\[url\]\s*(((?!")[\s\S])*?)(?:"[\s\S]*?)?\s*\[\/url\]/ig,'<a href="$1">$1</a>');b=b.replace(/\[url\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]\s*([\s\S]*?)\s*\[\/url\]/ig,'<a href="$1">$2</a>');b=b.replace(/\[email\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/email\]/ig,'<a href="mailto:$1">$1</a>');b=b.replace(/\[email\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]\s*([\s\S]+?)\s*\[\/email\]/ig,'<a href="mailto:$1">$2</a>');b=b.replace(/\[quote\]([\s\S]*?)\[\/quote\]/ig,"<blockquote>$1</blockquote>");b=b.replace(/\[flash\s*(?:=\s*(\d+)\s*,\s*(\d+)\s*)?\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/flash\]/ig,
  5. function(a,h,i,l){h||(h=480);i||(i=400);return'<embed type="application/x-shockwave-flash" src="'+l+'" wmode="opaque" quality="high" bgcolor="#ffffff" menu="false" play="true" loop="true" width="'+h+'" height="'+i+'"/>'});b=b.replace(/\[media\s*(?:=\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d+)\s*)?)?\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/media\]/ig,function(a,h,i,l,e){h||(h=480);i||(i=400);return'<embed type="application/x-mplayer2" src="'+e+'" enablecontextmenu="false" autostart="'+(l=="1"?"true":"false")+
  6. '" width="'+h+'" height="'+i+'"/>'});b=b.replace(/\[table\s*(?:=\s*(\d{1,4}%?)\s*(?:,\s*([^\]"]+)(?:"[^\]]*?)?)?)?\s*\]/ig,function(a,h,i){a="<table";if(h)a+=' width="'+h+'"';if(i)a+=' bgcolor="'+i+'"';return a+">"});b=b.replace(/\[tr\s*(?:=\s*([^\]"]+?)(?:"[^\]]*?)?)?\s*\]/ig,function(a,h){return"<tr"+(h?' bgcolor="'+h+'"':"")+">"});b=b.replace(/\[td\s*(?:=\s*(\d{1,2})\s*,\s*(\d{1,2})\s*(?:,\s*(\d{1,4}%?))?)?\s*\]/ig,function(a,h,i,l){return"<td"+(h>1?' colspan="'+h+'"':"")+(i>1?' rowspan="'+i+'"':
  7. "")+(l?' width="'+l+'"':"")+">"});b=b.replace(/\[\/(table|tr|td)\]/ig,"</$1>");b=b.replace(/\[\*\]((?:(?!\[\*\]|\[\/list\]|\[list\s*(?:=[^\]]+)?\])[\s\S])+)/ig,"<li>$1</li>");b=b.replace(/\[list\s*(?:=\s*([^\]"]+?)(?:"[^\]]*?)?)?\s*\]/ig,function(a,h){var i="<ul";if(h)i+=' type="'+h+'"';return i+">"});b=b.replace(/\[\/list\]/ig,"</ul>");b=b.replace(/\[hr\/\]/ig,"<hr />");for(g=1;g<=n;g++)b=b.replace("[\tubbcodeplace_"+g+"\t]",m[g]);return b=b.replace(/(^|<\/?\w+(?:\s+[^>]*?)?>)([^<$]+)/ig,function(a,
  8. h,i){return h+i.replace(/[\t ]/g,function(l){return{"\t":"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"," ":"&nbsp;"}[l]})})}
  9. function html2ubb(g){function o(e){var c;if(c=e.match(/\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i)){for(e=(c[1]*65536+c[2]*256+c[3]*1).toString(16);e.length<6;)e="0"+e;e="#"+e}return e=e.replace(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i,"#$1$1$2$2$3$3")}var b=/\s+src\s*=\s*(["']?)\s*(.+?)\s*\1(\s|$)/i,m=/\s+width\s*=\s*(["']?)\s*(\d+(?:\.\d+)?%?)\s*\1(\s|$)/i,n=/\s+height\s*=\s*(["']?)\s*(\d+(?:\.\d+)?%?)\s*\1(\s|$)/i,s=/(?:background|background-color|bgcolor)\s*[:=]\s*(["']?)\s*((rgb\s*\(\s*\d{1,3}%?,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\))|(#[0-9a-f]{3,6})|([a-z]{1,20}))\s*\1/i,
  10. a=String(g),h=[],i=0;a=a.replace(/\s*\r?\n\s*/g,"");a=a.replace(/<(script|style)(\s+[^>]*?)?>[\s\S]*?<\/\1>/ig,"");a=a.replace(/<!--[\s\S]*?--\>/ig,"");a=a.replace(/<br\s*?\/?>/ig,"\r\n");a=a.replace(/\[code\s*(=\s*([^\]]+?))?\]([\s\S]*?)\[\/code\]/ig,function(e){i++;h[i]=e;return"[\tubbcodeplace_"+i+"\t]"});a=a.replace(/<(\/?)(b|u|i|s)(\s+[^>]*?)?>/ig,"[$1$2]");a=a.replace(/<(\/?)strong(\s+[^>]*?)?>/ig,"[$1b]");a=a.replace(/<(\/?)em(\s+[^>]*?)?>/ig,"[$1i]");a=a.replace(/<(\/?)(strike|del)(\s+[^>]*?)?>/ig,
  11. "[$1s]");a=a.replace(/<(\/?)(sup|sub)(\s+[^>]*?)?>/ig,"[$1$2]");for(g=0;g<3;g++)a=a.replace(/<(span)(?:\s+[^>]*?)?\s+style\s*=\s*"((?:[^"]*?;)*\s*(?:font-family|font-size|color|background|background-color)\s*:[^"]*)"(?: [^>]+)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,function(e,c,d,f){e=d.match(/(?:^|;)\s*font-family\s*:\s*([^;]+)/i);c=d.match(/(?:^|;)\s*font-size\s*:\s*([^;]+)/i);var j=d.match(/(?:^|;)\s*color\s*:\s*([^;]+)/i);
  12. d=d.match(/(?:^|;)\s*(?:background|background-color)\s*:\s*([^;]+)/i);f=f;if(e)f="[font="+e[1]+"]"+f+"[/font]";if(c)f="[size="+c[1]+"]"+f+"[/size]";if(j)f="[color="+o(j[1])+"]"+f+"[/color]";if(d)f="[back="+o(d[1])+"]"+f+"[/back]";return f});for(g=0;g<3;g++)a=a.replace(/<(div|p)(?:\s+[^>]*?)?[\s"';]\s*(?:text-)?align\s*[=:]\s*(["']?)\s*(left|center|right)\s*\2[^>]*>(((?!<\1(\s+[^>]*?)?>)[\s\S])+?)<\/\1>/ig,"[align=$3]$4[/align]");for(g=0;g<3;g++)a=a.replace(/<(center)(?:\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S])*?)<\/\1>/ig,
  13. "[align=center]$2[/align]");for(g=0;g<3;g++)a=a.replace(/<(p|div)(?:\s+[^>]*?)?\s+style\s*=\s*"((?:[^"]*?;)*\s*text-align\s*:[^"]*)"(?: [^>]+)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,function(){});a=a.replace(/<a(?:\s+[^>]*?)?\s+href=(["'])\s*(.+?)\s*\1[^>]*>\s*([\s\S]*?)\s*<\/a>/ig,function(e,c,d,f){if(!(d&&f))return"";e="url";if(d.match(/^mailto:/i)){e="email";d=d.replace(/mailto:(.+?)/i,
  14. "$1")}c="["+e;if(d!=f)c+="="+d;return c+"]"+f+"[/"+e+"]"});a=a.replace(/<img(\s+[^>]*?)\/?>/ig,function(e,c){var d=c.match(/\s+emot\s*=\s*(["']?)\s*(.+?)\s*\1(\s|$)/i);if(d)return"[emot="+d[2]+"/]";d=c.match(b);var f=c.match(/\s+alt\s*=\s*(["']?)\s*(.*?)\s*\1(\s|$)/i),j=c.match(m),k=c.match(n),p=c.match(/\s+align\s*=\s*(["']?)\s*(\w+)\s*\1(\s|$)/i),q="[img",r="";if(!d)return"";r+=f[2];if(j||k)r+=","+(j?j[2]:"")+","+(k?k[2]:"");if(p)r+=","+p[2];if(r)q+="="+r;q+="]"+d[2]+"[/img]";return q});a=a.replace(/<blockquote(?:\s+[^>]*?)?>([\s\S]+?)<\/blockquote>/ig,
  15. "[quote]$1[/quote]");a=a.replace(/<embed((?:\s+[^>]*?)?(?:\s+type\s*=\s*"\s*application\/x-shockwave-flash\s*"|\s+classid\s*=\s*"\s*clsid:d27cdb6e-ae6d-11cf-96b8-4445535400000\s*")[^>]*?)\/?>/ig,function(e,c){var d=c.match(b),f=c.match(m),j=c.match(n),k="[flash";if(!d)return"";if(f&&j)k+="="+f[2]+","+j[2];k+="]"+d[2];return k+"[/flash]"});a=a.replace(/<embed((?:\s+[^>]*?)?(?:\s+type\s*=\s*"\s*application\/x-mplayer2\s*"|\s+classid\s*=\s*"\s*clsid:6bf52a52-394a-11d3-b153-00c04f79faa6\s*")[^>]*?)\/?>/ig,
  16. function(e,c){var d=c.match(b),f=c.match(m),j=c.match(n),k=c.match(/\s+autostart\s*=\s*(["']?)\s*(.+?)\s*\1(\s|$)/i),p="[media",q="0";if(!d)return"";if(k)if(k[2]=="true")q="1";if(f&&j)p+="="+f[2]+","+j[2]+","+q;p+="]"+d[2];return p+"[/media]"});a=a.replace(/<table(\s+[^>]*?)?>/ig,function(e,c){var d="[table";if(c){var f=c.match(m),j=c.match(s);if(f){d+="="+f[2];if(j)d+=","+j[2]}}return d+"]"});a=a.replace(/<tr(\s+[^>]*?)?>/ig,function(e,c){var d="[tr";if(c){var f=c.match(s);if(f)d+="="+f[2]}return d+
  17. "]"});a=a.replace(/<(?:th|td)(\s+[^>]*?)?>/ig,function(e,c){var d="[td";if(c){var f=c.match(/\s+colspan\s*=\s*(["']?)\s*(\d+)\s*\1(\s|$)/i),j=c.match(/\s+rowspan\s*=\s*(["']?)\s*(\d+)\s*\1(\s|$)/i),k=c.match(m);f=f?f[2]:1;j=j?j[2]:1;if(f>1||j>1||k)d+="="+f+","+j;if(k)d+=","+k[2]}return d+"]"});a=a.replace(/<\/(table|tr)>/ig,"[/$1]");a=a.replace(/<\/(th|td)>/ig,"[/td]");a=a.replace(/<ul(\s+[^>]*?)?>/ig,function(e,c){var d;if(c)d=c.match(/\s+type\s*=\s*(["']?)\s*(.+?)\s*\1(\s|$)/i);return"[list"+(d?
  18. "="+d[2]:"")+"]"});a=a.replace(/<ol(\s+[^>]*?)?>/ig,"[list=1]");a=a.replace(/<li(\s+[^>]*?)?>/ig,"[*]");a=a.replace(/<\/li>/ig,"");a=a.replace(/<\/(ul|ol)>/ig,"[/list]");a=a.replace(/<h([1-6])(\s+[^>]*?)?>/ig,function(e,c){return"\r\n\r\n[size="+(7-c)+"][b]"});a=a.replace(/<\/h[1-6]>/ig,"[/b][/size]\r\n\r\n");a=a.replace(/<address(\s+[^>]*?)?>/ig,"\r\n[i]");a=a.replace(/<\/address>/ig,"[i]\r\n");a=a.replace(/<hr(\s+[^>]*?)?\/>/ig,"[hr/]");for(g=0;g<3;g++)a=a.replace(/<(p)(?:\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,
  19. "\r\n\r\n$2\r\n\r\n");for(g=0;g<3;g++)a=a.replace(/<(div)(?:\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,"\r\n$2\r\n");a=a.replace(/((\s|&nbsp;)*\r?\n){3,}/g,"\r\n\r\n");a=a.replace(/^((\s|&nbsp;)*\r?\n)+/g,"");a=a.replace(/((\s|&nbsp;)*\r?\n)+$/g,"");for(g=1;g<=i;g++)a=a.replace("[\tubbcodeplace_"+g+"\t]",h[g]);a=a.replace(/<[^<>]+?>/g,"");var l={lt:"<",gt:">",nbsp:" ",amp:"&",quot:'"'};
  20. return a=a.replace(/&(lt|gt|nbsp|amp|quot);/ig,function(e,c){return l[c]})};