ubb.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*!
  2. * WYSIWYG UBB Editor support for xhEditor
  3. * @requires xhEditor
  4. *
  5. * @author Yanis.Wang<yanis.wang@gmail.com>
  6. * @site http://xheditor.com/
  7. * @licence LGPL(http://www.opensource.org/licenses/lgpl-license.php)
  8. *
  9. * @Version: 0.9.12 (build 120228)
  10. */
  11. function ubb2html(sUBB)
  12. {
  13. var i,sHtml=String(sUBB),arrcode=new Array(),cnum=0;
  14. var arrFontsize=['10px','13px','16px','18px','24px','32px','48px'];
  15. sHtml=sHtml.replace(/[<>&"]/g,function(c){return {'<':'&lt;','>':'&gt;','&':'&amp;','"':'&quot;'}[c];});
  16. sHtml=sHtml.replace(/\r?\n/g,"<br />");
  17. sHtml=sHtml.replace(/\[code\s*(?:=\s*([^\]]+?))?\]([\s\S]*?)\[\/code\]/ig,function(all,t,c){//code特殊处理
  18. cnum++;arrcode[cnum]=all;
  19. return "[\tubbcodeplace_"+cnum+"\t]";
  20. });
  21. sHtml=sHtml.replace(/\[(\/?)(b|u|i|s|sup|sub)\]/ig,'<$1$2>');
  22. sHtml=sHtml.replace(/\[color\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/ig,'<font color="$1">');
  23. sHtml=sHtml.replace(/\[font\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/ig,'<font face="$1">');
  24. sHtml=sHtml.replace(/\[\/(color|font)\]/ig,'</font>');
  25. sHtml=sHtml.replace(/\[size\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/ig,function(all,size){
  26. if(size.match(/^\d+$/))size=arrFontsize[size-1];
  27. return '<span style="font-size:'+size+';">';
  28. });
  29. sHtml=sHtml.replace(/\[back\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/ig,'<span style="background-color:$1;">');
  30. sHtml=sHtml.replace(/\[\/(size|back)\]/ig,'</span>');
  31. for(i=0;i<3;i++)sHtml=sHtml.replace(/\[align\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\](((?!\[align(?:\s+[^\]]+)?\])[\s\S])*?)\[\/align\]/ig,'<p align="$1">$2</p>');
  32. sHtml=sHtml.replace(/\[img\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/img\]/ig,'<img src="$1" alt="" />');
  33. sHtml=sHtml.replace(/\[img\s*=([^,\]]*)(?:\s*,\s*(\d*%?)\s*,\s*(\d*%?)\s*)?(?:,?\s*(\w+))?\s*\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*)?\s*\[\/img\]/ig,function(all,alt,p1,p2,p3,src){
  34. var str='<img src="'+src+'" alt="'+alt+'"',a=p3?p3:(!isNum(p1)?p1:'');
  35. if(isNum(p1))str+=' width="'+p1+'"';
  36. if(isNum(p2))str+=' height="'+p2+'"'
  37. if(a)str+=' align="'+a+'"';
  38. str+=' />';
  39. return str;
  40. });
  41. sHtml=sHtml.replace(/\[emot\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\/\]/ig,'<img emot="$1" />');
  42. sHtml=sHtml.replace(/\[url\]\s*(((?!")[\s\S])*?)(?:"[\s\S]*?)?\s*\[\/url\]/ig,'<a href="$1">$1</a>');
  43. sHtml=sHtml.replace(/\[url\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]\s*([\s\S]*?)\s*\[\/url\]/ig,'<a href="$1">$2</a>');
  44. sHtml=sHtml.replace(/\[email\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/email\]/ig,'<a href="mailto:$1">$1</a>');
  45. sHtml=sHtml.replace(/\[email\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]\s*([\s\S]+?)\s*\[\/email\]/ig,'<a href="mailto:$1">$2</a>');
  46. sHtml=sHtml.replace(/\[quote\]/ig,'<blockquote>');
  47. sHtml=sHtml.replace(/\[\/quote\]/ig,'</blockquote>');
  48. sHtml=sHtml.replace(/\[flash\s*(?:=\s*(\d+)\s*,\s*(\d+)\s*)?\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/flash\]/ig,function(all,w,h,url){
  49. if(!w)w=480;if(!h)h=400;
  50. return '<embed type="application/x-shockwave-flash" src="'+url+'" wmode="opaque" quality="high" bgcolor="#ffffff" menu="false" play="true" loop="true" width="'+w+'" height="'+h+'"/>';
  51. });
  52. sHtml=sHtml.replace(/\[media\s*(?:=\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d+)\s*)?)?\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/media\]/ig,function(all,w,h,play,url){
  53. if(!w)w=480;if(!h)h=400;
  54. return '<embed type="application/x-mplayer2" src="'+url+'" enablecontextmenu="false" autostart="'+(play=='1'?'true':'false')+'" width="'+w+'" height="'+h+'"/>';
  55. });
  56. sHtml=sHtml.replace(/\[table\s*(?:=\s*(\d{1,4}%?)\s*(?:,\s*([^\]"]+)(?:"[^\]]*?)?)?)?\s*\]/ig,function(all,w,b){
  57. var str='<table';
  58. if(w)str+=' width="'+w+'"';
  59. if(b)str+=' bgcolor="'+b+'"';
  60. return str+'>';
  61. });
  62. sHtml=sHtml.replace(/\[tr\s*(?:=\s*([^\]"]+?)(?:"[^\]]*?)?)?\s*\]/ig,function(all,bg){
  63. return '<tr'+(bg?' bgcolor="'+bg+'"':'')+'>';
  64. });
  65. sHtml=sHtml.replace(/\[td\s*(?:=\s*(\d{1,2})\s*,\s*(\d{1,2})\s*(?:,\s*(\d{1,4}%?))?)?\s*\]/ig,function(all,col,row,w){
  66. return '<td'+(col>1?' colspan="'+col+'"':'')+(row>1?' rowspan="'+row+'"':'')+(w?' width="'+w+'"':'')+'>';
  67. });
  68. sHtml=sHtml.replace(/\[\/(table|tr|td)\]/ig,'</$1>');
  69. sHtml=sHtml.replace(/\[\*\]((?:(?!\[\*\]|\[\/list\]|\[list\s*(?:=[^\]]+)?\])[\s\S])+)/ig,'<li>$1</li>');
  70. sHtml=sHtml.replace(/\[list\s*(?:=\s*([^\]"]+?)(?:"[^\]]*?)?)?\s*\]/ig,function(all,type){
  71. var str='<ul';
  72. if(type)str+=' type="'+type+'"';
  73. return str+'>';
  74. });
  75. sHtml=sHtml.replace(/\[\/list\]/ig,'</ul>');
  76. sHtml=sHtml.replace(/\[hr\/\]/ig,'<hr />');
  77. for(i=1;i<=cnum;i++)sHtml=sHtml.replace("[\tubbcodeplace_"+i+"\t]", arrcode[i]);
  78. sHtml=sHtml.replace(/(^|<\/?\w+(?:\s+[^>]*?)?>)([^<$]+)/ig, function(all,tag,text){
  79. return tag+text.replace(/[\t ]/g,function(c){return {'\t':'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',' ':'&nbsp;'}[c];});
  80. });
  81. function isNum(s){if(s!=null&&s!='')return !isNaN(s);else return false;}
  82. return sHtml;
  83. }
  84. function html2ubb(sHtml)
  85. {
  86. var regSrc=/\s+src\s*=\s*(["']?)\s*(.+?)\s*\1(\s|$)/i,regWidth=/\s+width\s*=\s*(["']?)\s*(\d+(?:\.\d+)?%?)\s*\1(\s|$)/i,regHeight=/\s+height\s*=\s*(["']?)\s*(\d+(?:\.\d+)?%?)\s*\1(\s|$)/i,regBg=/(?: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
  87. var i,sUBB=String(sHtml),arrcode=new Array(),cnum=0;
  88. sUBB=sUBB.replace(/[ \t]*\r?\n[ \t]*/g,'');
  89. sUBB = sUBB.replace(/<(script|style)(\s+[^>]*?)?>[\s\S]*?<\/\1>/ig, '');
  90. sUBB = sUBB.replace(/<!--[\s\S]*?-->/ig,'');
  91. sUBB=sUBB.replace(/<br(\s+[^>]*)?\/?>/ig,"\r\n");
  92. sUBB=sUBB.replace(/\[code\s*(=\s*([^\]]+?))?\]([\s\S]*?)\[\/code\]/ig,function(all,t,c){//code特殊处理
  93. cnum++;arrcode[cnum]=all;
  94. return "[\tubbcodeplace_"+cnum+"\t]";
  95. });
  96. sUBB=sUBB.replace(/<(\/?)(b|u|i|s)(\s+[^>]*?)?>/ig,'[$1$2]');
  97. sUBB=sUBB.replace(/<(\/?)strong(\s+[^>]*?)?>/ig,'[$1b]');
  98. sUBB=sUBB.replace(/<(\/?)em(\s+[^>]*?)?>/ig,'[$1i]');
  99. sUBB=sUBB.replace(/<(\/?)(strike|del)(\s+[^>]*?)?>/ig,'[$1s]');
  100. sUBB=sUBB.replace(/<(\/?)(sup|sub)(\s+[^>]*?)?>/ig,'[$1$2]');
  101. //font转ubb
  102. function font2ubb(all,tag,attrs,content)
  103. {
  104. if(!attrs)return content;
  105. var arrStart=[],arrEnd=[];
  106. var match;
  107. match=attrs.match(/ face\s*=\s*"\s*([^"]+)\s*"/i);
  108. if(match){
  109. arrStart.push('[font='+match[1]+']');
  110. arrEnd.push('[/font]');
  111. }
  112. match=attrs.match(/ size\s*=\s*"\s*(\d+)\s*"/i);
  113. if(match){
  114. arrStart.push('[size='+match[1]+']');
  115. arrEnd.push('[/size]');
  116. }
  117. match=attrs.match(/ color\s*=\s*"\s*([^"]+)\s*"/i);
  118. if(match){
  119. arrStart.push('[color='+formatColor(match[1])+']');
  120. arrEnd.push('[/color]');
  121. }
  122. return arrStart.join('')+content+arrEnd.join('');
  123. }
  124. sUBB = sUBB.replace(/<(font)(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,font2ubb);//第3层
  125. sUBB = sUBB.replace(/<(font)(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?)<\/\1>/ig,font2ubb);//第2层
  126. sUBB = sUBB.replace(/<(font)(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S])*?)<\/\1>/ig,font2ubb);//最里层
  127. for(i=0;i<3;i++)sUBB=sUBB.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(all,tag,style,content){
  128. var face=style.match(/(?:^|;)\s*font-family\s*:\s*([^;]+)/i),size=style.match(/(?:^|;)\s*font-size\s*:\s*([^;]+)/i),color=style.match(/(?:^|;)\s*color\s*:\s*([^;]+)/i),back=style.match(/(?:^|;)\s*(?:background|background-color)\s*:\s*([^;]+)/i),str=content;
  129. var arrStart=[],arrEnd=[];
  130. if(face){
  131. arrStart.push('[font='+face[1]+']');
  132. arrEnd.push('[/font]');
  133. }
  134. if(size){
  135. arrStart.push('[size='+size[1]+']');
  136. arrEnd.push('[/size]');
  137. }
  138. if(color){
  139. arrStart.push('[color='+formatColor(color[1])+']');
  140. arrEnd.push('[/color]');
  141. }
  142. if(back){
  143. arrStart.push('[back='+formatColor(back[1])+']');
  144. arrEnd.push('[/back]');
  145. }
  146. return arrStart.join('')+str+arrEnd.join('');
  147. });
  148. function formatColor(c)
  149. {
  150. var matchs;
  151. if(matchs=c.match(/\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i)){c=(matchs[1]*65536+matchs[2]*256+matchs[3]*1).toString(16);while(c.length<6)c='0'+c;c='#'+c;}
  152. c=c.replace(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i,'#$1$1$2$2$3$3');
  153. return c;
  154. }
  155. for(i=0;i<3;i++)sUBB=sUBB.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]');
  156. for(i=0;i<3;i++)sUBB=sUBB.replace(/<(center)(?:\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S])*?)<\/\1>/ig,'[align=center]$2[/align]');
  157. for(i=0;i<3;i++)sUBB=sUBB.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(all,tag,align,content){
  158. return '[align='+align+']'+content+'[/align]';
  159. });
  160. sUBB=sUBB.replace(/<a(?:\s+[^>]*?)?\s+href=(["'])\s*(.+?)\s*\1[^>]*>\s*([\s\S]*?)\s*<\/a>/ig,function(all,q,url,text){
  161. if(!(url&&text))return '';
  162. var tag='url',str;
  163. if(url.match(/^mailto:/i))
  164. {
  165. tag='email';
  166. url=url.replace(/mailto:(.+?)/i,'$1');
  167. }
  168. str='['+tag;
  169. if(url!=text)str+='='+url;
  170. return str+']'+text+'[/'+tag+']';
  171. });
  172. sUBB=sUBB.replace(/<img(\s+[^>]*?)\/?>/ig,function(all,attr){
  173. var emot=attr.match(/\s+emot\s*=\s*(["']?)\s*(.+?)\s*\1(\s|$)/i);
  174. if(emot)return '[emot='+emot[2]+'/]';
  175. var url=attr.match(regSrc),alt=attr.match(/\s+alt\s*=\s*(["']?)\s*(.*?)\s*\1(\s|$)/i),w=attr.match(regWidth),h=attr.match(regHeight),align=attr.match(/\s+align\s*=\s*(["']?)\s*(\w+)\s*\1(\s|$)/i),str='[img',p='';
  176. if(!url)return '';
  177. p+=alt[2];
  178. if(w||h)p+=','+(w?w[2]:'')+','+(h?h[2]:'');
  179. if(align)p+=','+align[2];
  180. if(p)str+='='+p;
  181. str+=']'+url[2]+'[/img]';
  182. return str;
  183. });
  184. sUBB=sUBB.replace(/<blockquote(?:\s+[^>]*?)?>/ig,'[quote]');
  185. sUBB=sUBB.replace(/<\/blockquote>/ig,'[/quote]');
  186. sUBB=sUBB.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(all,attr){
  187. var url=attr.match(regSrc),w=attr.match(regWidth),h=attr.match(regHeight),str='[flash';
  188. if(!url)return '';
  189. if(w&&h)str+='='+w[2]+','+h[2];
  190. str+=']'+url[2];
  191. return str+'[/flash]';
  192. });
  193. sUBB=sUBB.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,function(all,attr){
  194. var url=attr.match(regSrc),w=attr.match(regWidth),h=attr.match(regHeight),p=attr.match(/\s+autostart\s*=\s*(["']?)\s*(.+?)\s*\1(\s|$)/i),str='[media',auto='0';
  195. if(!url)return '';
  196. if(p)if(p[2]=='true')auto='1';
  197. if(w&&h)str+='='+w[2]+','+h[2]+','+auto;
  198. str+=']'+url[2];
  199. return str+'[/media]';
  200. });
  201. sUBB=sUBB.replace(/<table(\s+[^>]*?)?>/ig,function(all,attr){
  202. var str='[table';
  203. if(attr)
  204. {
  205. var w=attr.match(regWidth),b=attr.match(regBg);
  206. if(w)
  207. {
  208. str+='='+w[2];
  209. if(b)str+=','+b[2];
  210. }
  211. }
  212. return str+']';
  213. });
  214. sUBB=sUBB.replace(/<tr(\s+[^>]*?)?>/ig,function(all,attr){
  215. var str='[tr';
  216. if(attr)
  217. {
  218. var bg=attr.match(regBg)
  219. if(bg)str+='='+bg[2];
  220. }
  221. return str+']';
  222. });
  223. sUBB=sUBB.replace(/<(?:th|td)(\s+[^>]*?)?>/ig,function(all,attr){
  224. var str='[td';
  225. if(attr)
  226. {
  227. var col=attr.match(/\s+colspan\s*=\s*(["']?)\s*(\d+)\s*\1(\s|$)/i),row=attr.match(/\s+rowspan\s*=\s*(["']?)\s*(\d+)\s*\1(\s|$)/i),w=attr.match(regWidth);
  228. col=col?col[2]:1;
  229. row=row?row[2]:1;
  230. if(col>1||row>1||w)str+='='+col+','+row;
  231. if(w)str+=','+w[2];
  232. }
  233. return str+']';
  234. });
  235. sUBB=sUBB.replace(/<\/(table|tr)>/ig,'[/$1]');
  236. sUBB=sUBB.replace(/<\/(th|td)>/ig,'[/td]');
  237. sUBB=sUBB.replace(/<ul(\s+[^>]*?)?>/ig,function(all,attr){
  238. var t;
  239. if(attr)t=attr.match(/\s+type\s*=\s*(["']?)\s*(.+?)\s*\1(\s|$)/i);
  240. return '[list'+(t?'='+t[2]:'')+']';
  241. });
  242. sUBB=sUBB.replace(/<ol(\s+[^>]*?)?>/ig,'[list=1]');
  243. sUBB=sUBB.replace(/<li(\s+[^>]*?)?>/ig,'[*]');
  244. sUBB=sUBB.replace(/<\/li>/ig,'');
  245. sUBB=sUBB.replace(/<\/(ul|ol)>/ig,'[/list]');
  246. sUBB=sUBB.replace(/<h([1-6])(\s+[^>]*?)?>/ig,function(all,n){return '\r\n\r\n[size='+(7-n)+'][b]'});
  247. sUBB=sUBB.replace(/<\/h[1-6]>/ig,'[/b][/size]\r\n\r\n');
  248. sUBB=sUBB.replace(/<address(\s+[^>]*?)?>/ig,'\r\n[i]');
  249. sUBB=sUBB.replace(/<\/address>/ig,'[i]\r\n');
  250. sUBB=sUBB.replace(/<hr(\s+[^>]*?)?\/>/ig,'[hr/]');
  251. for(i=0;i<3;i++)sUBB=sUBB.replace(/<(p)(?:\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,"\r\n\r\n$2\r\n\r\n");
  252. for(i=0;i<3;i++)sUBB=sUBB.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");
  253. sUBB=sUBB.replace(/((\s|&nbsp;)*\r?\n){3,}/g,"\r\n\r\n");//限制最多2次换行
  254. sUBB=sUBB.replace(/^((\s|&nbsp;)*\r?\n)+/g,'');//清除开头换行
  255. sUBB=sUBB.replace(/((\s|&nbsp;)*\r?\n)+$/g,'');//清除结尾换行
  256. for(i=1;i<=cnum;i++)sUBB=sUBB.replace("[\tubbcodeplace_"+i+"\t]", arrcode[i]);
  257. sUBB=sUBB.replace(/<[^<>]+?>/g,'');//删除所有HTML标签
  258. var arrEntities={'lt':'<','gt':'>','nbsp':' ','amp':'&','quot':'"'};
  259. sUBB=sUBB.replace(/&(lt|gt|nbsp|amp|quot);/ig,function(all,t){return arrEntities[t];});
  260. //清除空内容的UBB标签
  261. sUBB=sUBB.replace(/\[([a-z]+)(?:=[^\[\]]+)?\]\s*\[\/\1\]/ig,'');
  262. return sUBB;
  263. }