All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.web.lib.editor.xheditor_plugins.ubb.js Maven / Gradle / Ivy

There is a newer version: 6.2.04
Show newest version
/*!
 * WYSIWYG UBB Editor support for xhEditor
 * @requires xhEditor
 * 
 * @author Yanis.Wang
 * @site http://xheditor.com/
 * @licence LGPL(http://www.opensource.org/licenses/lgpl-license.php)
 * 
 * @Version: 0.9.12 (build 120228)
 */
;function ubb2html(l){var h,j=String(l),n=new Array(),i=0;var m=["10px","13px","16px","18px","24px","32px","48px"];j=j.replace(/[<>&"]/g,function(a){return{"<":"<",">":">","&":"&",'"':"""}[a]});j=j.replace(/\r?\n/g,"
");j=j.replace(/\[code\s*(?:=\s*([^\]]+?))?\]([\s\S]*?)\[\/code\]/ig,function(b,c,a){i++;n[i]=b;return"[\tubbcodeplace_"+i+"\t]"});j=j.replace(/\[(\/?)(b|u|i|s|sup|sub)\]/ig,"<$1$2>");j=j.replace(/\[color\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/ig,'');j=j.replace(/\[font\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/ig,'');j=j.replace(/\[\/(color|font)\]/ig,"");j=j.replace(/\[size\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/ig,function(a,b){if(b.match(/^\d+$/)){b=m[b-1]}return''});j=j.replace(/\[back\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/ig,'');j=j.replace(/\[\/(size|back)\]/ig,"");for(h=0;h<3;h++){j=j.replace(/\[align\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\](((?!\[align(?:\s+[^\]]+)?\])[\s\S])*?)\[\/align\]/ig,'

$2

')}j=j.replace(/\[img\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/img\]/ig,'');j=j.replace(/\[img\s*=([^,\]]*)(?:\s*,\s*(\d*%?)\s*,\s*(\d*%?)\s*)?(?:,?\s*(\w+))?\s*\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*)?\s*\[\/img\]/ig,function(e,b,g,c,d,p){var a=''+b+'');j=j.replace(/\[url\]\s*(((?!")[\s\S])*?)(?:"[\s\S]*?)?\s*\[\/url\]/ig,'$1');j=j.replace(/\[url\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]\s*([\s\S]*?)\s*\[\/url\]/ig,'$2');j=j.replace(/\[email\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/email\]/ig,'$1');j=j.replace(/\[email\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]\s*([\s\S]+?)\s*\[\/email\]/ig,'$2');j=j.replace(/\[quote\]/ig,"
");j=j.replace(/\[\/quote\]/ig,"
");j=j.replace(/\[flash\s*(?:=\s*(\d+)\s*,\s*(\d+)\s*)?\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/flash\]/ig,function(a,d,b,c){if(!d){d=480}if(!b){b=400}return''});j=j.replace(/\[media\s*(?:=\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d+)\s*)?)?\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/media\]/ig,function(b,e,c,a,d){if(!e){e=480}if(!c){c=400}return''});j=j.replace(/\[table\s*(?:=\s*(\d{1,4}%?)\s*(?:,\s*([^\]"]+)(?:"[^\]]*?)?)?)?\s*\]/ig,function(b,c,d){var a=""});j=j.replace(/\[tr\s*(?:=\s*([^\]"]+?)(?:"[^\]]*?)?)?\s*\]/ig,function(a,b){return""});j=j.replace(/\[td\s*(?:=\s*(\d{1,2})\s*,\s*(\d{1,2})\s*(?:,\s*(\d{1,4}%?))?)?\s*\]/ig,function(b,c,a,d){return"1?' colspan="'+c+'"':"")+(a>1?' rowspan="'+a+'"':"")+(d?' width="'+d+'"':"")+">"});j=j.replace(/\[\/(table|tr|td)\]/ig,"");j=j.replace(/\[\*\]((?:(?!\[\*\]|\[\/list\]|\[list\s*(?:=[^\]]+)?\])[\s\S])+)/ig,"
  • $1
  • ");j=j.replace(/\[list\s*(?:=\s*([^\]"]+?)(?:"[^\]]*?)?)?\s*\]/ig,function(b,c){var a=""});j=j.replace(/\[\/list\]/ig,"");j=j.replace(/\[hr\/\]/ig,"
    ");for(h=1;h<=i;h++){j=j.replace("[\tubbcodeplace_"+h+"\t]",n[h])}j=j.replace(/(^|<\/?\w+(?:\s+[^>]*?)?>)([^<$]+)/ig,function(b,c,a){return c+a.replace(/[\t ]/g,function(d){return{"\t":"        "," ":" "}[d]})});function k(a){if(a!=null&&a!=""){return !isNaN(a)}else{return false}}return j}function html2ubb(o){var w=/\s+src\s*=\s*(["']?)\s*(.+?)\s*\1(\s|$)/i,q=/\s+width\s*=\s*(["']?)\s*(\d+(?:\.\d+)?%?)\s*\1(\s|$)/i,x=/\s+height\s*=\s*(["']?)\s*(\d+(?:\.\d+)?%?)\s*\1(\s|$)/i,r=/(?: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;var v,t=String(o),p=new Array(),u=0;t=t.replace(/[ \t]*\r?\n[ \t]*/g,"");t=t.replace(/<(script|style)(\s+[^>]*?)?>[\s\S]*?<\/\1>/ig,"");t=t.replace(//ig,"");t=t.replace(/]*)?\/?>/ig,"\r\n");t=t.replace(/\[code\s*(=\s*([^\]]+?))?\]([\s\S]*?)\[\/code\]/ig,function(c,a,b){u++;p[u]=c;return"[\tubbcodeplace_"+u+"\t]"});t=t.replace(/<(\/?)(b|u|i|s)(\s+[^>]*?)?>/ig,"[$1$2]");t=t.replace(/<(\/?)strong(\s+[^>]*?)?>/ig,"[$1b]");t=t.replace(/<(\/?)em(\s+[^>]*?)?>/ig,"[$1i]");t=t.replace(/<(\/?)(strike|del)(\s+[^>]*?)?>/ig,"[$1s]");t=t.replace(/<(\/?)(sup|sub)(\s+[^>]*?)?>/ig,"[$1$2]");function s(c,a,d,b){if(!d){return b}var e=[],g=[];var f;f=d.match(/ face\s*=\s*"\s*([^"]+)\s*"/i);if(f){e.push("[font="+f[1]+"]");g.push("[/font]")}f=d.match(/ size\s*=\s*"\s*(\d+)\s*"/i);if(f){e.push("[size="+f[1]+"]");g.push("[/size]")}f=d.match(/ color\s*=\s*"\s*([^"]+)\s*"/i);if(f){e.push("[color="+i(f[1])+"]");g.push("[/color]")}return e.join("")+b+g.join("")}t=t.replace(/<(font)(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,s);t=t.replace(/<(font)(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?)<\/\1>/ig,s);t=t.replace(/<(font)(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S])*?)<\/\1>/ig,s);for(v=0;v<3;v++){t=t.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(j,g,f,a){var l=f.match(/(?:^|;)\s*font-family\s*:\s*([^;]+)/i),h=f.match(/(?:^|;)\s*font-size\s*:\s*([^;]+)/i),d=f.match(/(?:^|;)\s*color\s*:\s*([^;]+)/i),c=f.match(/(?:^|;)\s*(?:background|background-color)\s*:\s*([^;]+)/i),k=a;var e=[],b=[];if(l){e.push("[font="+l[1]+"]");b.push("[/font]")}if(h){e.push("[size="+h[1]+"]");b.push("[/size]")}if(d){e.push("[color="+i(d[1])+"]");b.push("[/color]")}if(c){e.push("[back="+i(c[1])+"]");b.push("[/back]")}return e.join("")+k+b.join("")})}function i(b){var a;if(a=b.match(/\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i)){b=(a[1]*65536+a[2]*256+a[3]*1).toString(16);while(b.length<6){b="0"+b}b="#"+b}b=b.replace(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i,"#$1$1$2$2$3$3");return b}for(v=0;v<3;v++){t=t.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(v=0;v<3;v++){t=t.replace(/<(center)(?:\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S])*?)<\/\1>/ig,"[align=center]$2[/align]")}for(v=0;v<3;v++){t=t.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(d,a,b,c){return"[align="+b+"]"+c+"[/align]"})}t=t.replace(/]*?)?\s+href=(["'])\s*(.+?)\s*\1[^>]*>\s*([\s\S]*?)\s*<\/a>/ig,function(e,d,f,b){if(!(f&&b)){return""}var a="url",c;if(f.match(/^mailto:/i)){a="email";f=f.replace(/mailto:(.+?)/i,"$1")}c="["+a;if(f!=b){c+="="+f}return c+"]"+b+"[/"+a+"]"});t=t.replace(/]*?)\/?>/ig,function(g,k){var h=k.match(/\s+emot\s*=\s*(["']?)\s*(.+?)\s*\1(\s|$)/i);if(h){return"[emot="+h[2]+"/]"}var e=k.match(w),c=k.match(/\s+alt\s*=\s*(["']?)\s*(.*?)\s*\1(\s|$)/i),f=k.match(q),b=k.match(x),a=k.match(/\s+align\s*=\s*(["']?)\s*(\w+)\s*\1(\s|$)/i),j="[img",d="";if(!e){return""}d+=c[2];if(f||b){d+=","+(f?f[2]:"")+","+(b?b[2]:"")}if(a){d+=","+a[2]}if(d){j+="="+d}j+="]"+e[2]+"[/img]";return j});t=t.replace(/]*?)?>/ig,"[quote]");t=t.replace(/<\/blockquote>/ig,"[/quote]");t=t.replace(/]*?)?(?:\s+type\s*=\s*"\s*application\/x-shockwave-flash\s*"|\s+classid\s*=\s*"\s*clsid:d27cdb6e-ae6d-11cf-96b8-4445535400000\s*")[^>]*?)\/?>/ig,function(c,a){var e=a.match(w),f=a.match(q),d=a.match(x),b="[flash";if(!e){return""}if(f&&d){b+="="+f[2]+","+d[2]}b+="]"+e[2];return b+"[/flash]"});t=t.replace(/]*?)?(?:\s+type\s*=\s*"\s*application\/x-mplayer2\s*"|\s+classid\s*=\s*"\s*clsid:6bf52a52-394a-11d3-b153-00c04f79faa6\s*")[^>]*?)\/?>/ig,function(e,c){var g=c.match(w),h=c.match(q),f=c.match(x),d=c.match(/\s+autostart\s*=\s*(["']?)\s*(.+?)\s*\1(\s|$)/i),b="[media",a="0";if(!g){return""}if(d){if(d[2]=="true"){a="1"}}if(h&&f){b+="="+h[2]+","+f[2]+","+a}b+="]"+g[2];return b+"[/media]"});t=t.replace(/]*?)?>/ig,function(c,e){var b="[table";if(e){var d=e.match(q),a=e.match(r);if(d){b+="="+d[2];if(a){b+=","+a[2]}}}return b+"]"});t=t.replace(/]*?)?>/ig,function(c,a){var b="[tr";if(a){var d=a.match(r);if(d){b+="="+d[2]}}return b+"]"});t=t.replace(/<(?:th|td)(\s+[^>]*?)?>/ig,function(d,a){var b="[td";if(a){var e=a.match(/\s+colspan\s*=\s*(["']?)\s*(\d+)\s*\1(\s|$)/i),c=a.match(/\s+rowspan\s*=\s*(["']?)\s*(\d+)\s*\1(\s|$)/i),f=a.match(q);e=e?e[2]:1;c=c?c[2]:1;if(e>1||c>1||f){b+="="+e+","+c}if(f){b+=","+f[2]}}return b+"]"});t=t.replace(/<\/(table|tr)>/ig,"[/$1]");t=t.replace(/<\/(th|td)>/ig,"[/td]");t=t.replace(/]*?)?>/ig,function(b,a){var c;if(a){c=a.match(/\s+type\s*=\s*(["']?)\s*(.+?)\s*\1(\s|$)/i)}return"[list"+(c?"="+c[2]:"")+"]"});t=t.replace(/]*?)?>/ig,"[list=1]");t=t.replace(/]*?)?>/ig,"[*]");t=t.replace(/<\/li>/ig,"");t=t.replace(/<\/(ul|ol)>/ig,"[/list]");t=t.replace(/]*?)?>/ig,function(a,b){return"\r\n\r\n[size="+(7-b)+"][b]"});t=t.replace(/<\/h[1-6]>/ig,"[/b][/size]\r\n\r\n");t=t.replace(/]*?)?>/ig,"\r\n[i]");t=t.replace(/<\/address>/ig,"[i]\r\n");t=t.replace(/]*?)?\/>/ig,"[hr/]");for(v=0;v<3;v++){t=t.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")}for(v=0;v<3;v++){t=t.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")}t=t.replace(/((\s| )*\r?\n){3,}/g,"\r\n\r\n");t=t.replace(/^((\s| )*\r?\n)+/g,"");t=t.replace(/((\s| )*\r?\n)+$/g,"");for(v=1;v<=u;v++){t=t.replace("[\tubbcodeplace_"+v+"\t]",p[v])}t=t.replace(/<[^<>]+?>/g,"");var n={lt:"<",gt:">",nbsp:" ",amp:"&",quot:'"'};t=t.replace(/&(lt|gt|nbsp|amp|quot);/ig,function(b,a){return n[a]});t=t.replace(/\[([a-z]+)(?:=[^\[\]]+)?\]\s*\[\/\1\]/ig,"");return t};




    © 2015 - 2024 Weber Informatics LLC | Privacy Policy