2 * editor_plugin_src.js
\r
4 * Copyright 2009, Moxiecode Systems AB
\r
5 * Released under LGPL License.
\r
7 * License: http://tinymce.moxiecode.com/license
\r
8 * Contributing: http://tinymce.moxiecode.com/contributing
\r
11 /* Macgirvin Aug-2010 changed from punbb to dfrn dialect */
\r
14 tinymce.create('tinymce.plugins.BBCodePlugin', {
\r
15 init : function(ed, url) {
\r
16 var t = this, dialect = ed.getParam('bbcode_dialect', 'dfrn').toLowerCase();
\r
18 ed.onBeforeSetContent.add(function(ed, o) {
\r
19 o.content = t['_' + dialect + '_bbcode2html'](o.content);
\r
22 ed.onPostProcess.add(function(ed, o) {
\r
24 o.content = t['_' + dialect + '_bbcode2html'](o.content);
\r
27 o.content = t['_' + dialect + '_html2bbcode'](o.content);
\r
31 getInfo : function() {
\r
33 longname : 'BBCode Plugin',
\r
34 author : 'Moxiecode Systems AB',
\r
35 authorurl : 'http://tinymce.moxiecode.com',
\r
36 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',
\r
37 version : tinymce.majorVersion + "." + tinymce.minorVersion
\r
43 // HTML -> BBCode in DFRN dialect
\r
44 _dfrn_html2bbcode : function(s) {
\r
45 s = tinymce.trim(s);
\r
47 function rep(re, str) {
\r
50 s = s.replace(re,str);
\r
52 //modify code to keep stuff intact within [code][/code] blocks
\r
53 //Waitman Gobble NO WARRANTY
\r
55 /* This doesn't seem to work well with
\r
58 commenting out for now
\r
62 var o = new Array();
\r
63 var x = s.split("[code]");
\r
68 si = si.replace(re,str);
\r
71 for (i = 0; i < x.length; i++) {
\r
72 var no = new Array();
\r
74 var g = j.split("[/code]");
\r
77 si = si.replace(re,str);
\r
79 o.push(no.join("[/code]"));
\r
82 s = o.join("[code]");
\r
90 function _h2b_cb(match) {
\r
92 function s_h2b(data) {
\r
98 data: {text: match},
\r
105 var f, g, tof = [], tor = [];
\r
106 var find_spanc = /<span [^>]*class *= *[\"'](?:[^\"']* )*oembed(?: [^\"']*)*[\"'][^>]*>(.*?(?:<span[^>]*>(.*?)<\/span *>)*.*?)<\/span *>/ig;
\r
107 while (f = find_spanc.exec(match)) {
\r
108 var find_a = /<a([^>]* rel=[\"']oembed[\"'][^>]*)>.*?<\/a *>/ig;
\r
109 if (g = find_a.exec(f[1])) {
\r
110 var find_href = /href=[\"']([^\"']*)[\"']/ig;
\r
111 var m2 = find_href.exec(g[1]);
\r
114 tor.push("[EMBED]" + m2[1] + "[/EMBED]");
\r
118 for (var i = 0; i < tof.length; i++) match = match.replace(tof[i], tor[i]);
\r
122 if (s.indexOf('class="oembed')>=0){
\r
123 //alert("request oembed html2bbcode");
\r
130 // example: <strong> to [b]
\r
131 rep(/<a class=\"bookmark\" href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[bookmark=$1]$2[/bookmark]");
\r
132 rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");
\r
133 rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");
\r
134 rep(/<span style=\"color:(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");
\r
135 rep(/<font>(.*?)<\/font>/gi,"$1");
\r
136 rep(/<img.*?width=\"(.*?)\".*?height=\"(.*?)\".*?src=\"(.*?)\".*?\/>/gi,"[img=$1x$2]$3[/img]");
\r
137 rep(/<img.*?height=\"(.*?)\".*?width=\"(.*?)\".*?src=\"(.*?)\".*?\/>/gi,"[img=$2x$1]$3[/img]");
\r
138 rep(/<img.*?src=\"(.*?)\".*?height=\"(.*?)\".*?width=\"(.*?)\".*?\/>/gi,"[img=$3x$2]$1[/img]");
\r
139 rep(/<img.*?src=\"(.*?)\".*?width=\"(.*?)\".*?height=\"(.*?)\".*?\/>/gi,"[img=$2x$3]$1[/img]");
\r
140 rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
\r
142 rep(/<ul class=\"listbullet\" style=\"list-style-type\: circle\;\">(.*?)<\/ul>/gi,"[list]$1[/list]");
\r
143 rep(/<ul class=\"listnone\" style=\"list-style-type\: none\;\">(.*?)<\/ul>/gi,"[list=]$1[/list]");
\r
144 rep(/<ul class=\"listdecimal\" style=\"list-style-type\: decimal\;\">(.*?)<\/ul>/gi,"[list=1]$1[/list]");
\r
145 rep(/<ul class=\"listlowerroman\" style=\"list-style-type\: lower-roman\;\">(.*?)<\/ul>/gi,"[list=i]$1[/list]");
\r
146 rep(/<ul class=\"listupperroman\" style=\"list-style-type\: upper-roman\;\">(.*?)<\/ul>/gi,"[list=I]$1[/list]");
\r
147 rep(/<ul class=\"listloweralpha\" style=\"list-style-type\: lower-alpha\;\">(.*?)<\/ul>/gi,"[list=a]$1[/list]");
\r
148 rep(/<ul class=\"listupperalpha\" style=\"list-style-type\: upper-alpha\;\">(.*?)<\/ul>/gi,"[list=A]$1[/list]");
\r
149 rep(/<li>(.*?)<\/li>/gi,'[li]$1[/li]');
\r
151 rep(/<code>(.*?)<\/code>/gi,"[code]$1[/code]");
\r
152 rep(/<\/(strong|b)>/gi,"[/b]");
\r
153 rep(/<(strong|b)>/gi,"[b]");
\r
154 rep(/<\/(em|i)>/gi,"[/i]");
\r
155 rep(/<(em|i)>/gi,"[i]");
\r
156 rep(/<\/u>/gi,"[/u]");
\r
157 rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");
\r
158 rep(/<u>/gi,"[u]");
\r
159 rep(/<blockquote[^>]*>/gi,"[quote]");
\r
160 rep(/<\/blockquote>/gi,"[/quote]");
\r
161 rep(/<hr \/>/gi,"[hr]");
\r
162 rep(/<br (.*?)\/>/gi,"\n");
\r
163 rep(/<br\/>/gi,"\n");
\r
164 rep(/<br>/gi,"\n");
\r
166 rep(/<\/p>/gi,"\n");
\r
167 rep(/ /gi," ");
\r
168 rep(/"/gi,"\"");
\r
171 rep(/&/gi,"&");
\r
176 // BBCode -> HTML from DFRN dialect
\r
177 _dfrn_bbcode2html : function(s) {
\r
178 s = tinymce.trim(s);
\r
181 function rep(re, str) {
\r
184 //modify code to keep stuff intact within [code][/code] blocks
\r
185 //Waitman Gobble NO WARRANTY
\r
188 var o = new Array();
\r
189 var x = s.split("[code]");
\r
194 si = si.replace(re,str);
\r
197 for (i = 0; i < x.length; i++) {
\r
198 var no = new Array();
\r
200 var g = j.split("[/code]");
\r
201 no.push(g.shift());
\r
203 si = si.replace(re,str);
\r
205 o.push(no.join("[/code]"));
\r
208 s = o.join("[code]");
\r
216 // example: [b] to <strong>
\r
217 rep(/\n/gi,"<br />");
\r
218 rep(/\[b\]/gi,"<strong>");
\r
219 rep(/\[\/b\]/gi,"</strong>");
\r
220 rep(/\[i\]/gi,"<em>");
\r
221 rep(/\[\/i\]/gi,"</em>");
\r
222 rep(/\[u\]/gi,"<u>");
\r
223 rep(/\[\/u\]/gi,"</u>");
\r
224 rep(/\[hr\]/gi,"<hr />");
\r
225 rep(/\[bookmark=([^\]]+)\](.*?)\[\/bookmark\]/gi,"<a class=\"bookmark\" href=\"$1\">$2</a>");
\r
226 rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");
\r
227 rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
\r
228 rep(/\[img=(.*?)x(.*?)\](.*?)\[\/img\]/gi,"<img width=\"$1\" height=\"$2\" src=\"$3\" />");
\r
229 rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
\r
231 rep(/\[list\](.*?)\[\/list\]/gi, '<ul class="listbullet" style="list-style-type: circle;">$1</ul>');
\r
232 rep(/\[list=\](.*?)\[\/list\]/gi, '<ul class="listnone" style="list-style-type: none;">$1</ul>');
\r
233 rep(/\[list=1\](.*?)\[\/list\]/gi, '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>');
\r
234 rep(/\[list=i\](.*?)\[\/list\]/gi,'<ul class="listlowerroman" style="list-style-type: lower-roman;">$1</ul>');
\r
235 rep(/\[list=I\](.*?)\[\/list\]/gi, '<ul class="listupperroman" style="list-style-type: upper-roman;">$1</ul>');
\r
236 rep(/\[list=a\](.*?)\[\/list\]/gi, '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$1</ul>');
\r
237 rep(/\[list=A\](.*?)\[\/list\]/gi, '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$1</ul>');
\r
238 rep(/\[li\](.*?)\[\/li\]/gi, '<li>$1</li>');
\r
239 rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<span style=\"color: $1;\">$2</span>");
\r
240 rep(/\[size=(.*?)\](.*?)\[\/size\]/gi,"<span style=\"font-size: $1;\">$2</span>");
\r
241 rep(/\[code\](.*?)\[\/code\]/gi,"<code>$1</code>");
\r
242 rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<blockquote>$1</blockquote>");
\r
245 function _b2h_cb(match, url) {
\r
246 url = bin2hex(url);
\r
247 function s_b2h(data) {
\r
251 url: 'oembed/b2h?url=' + url,
\r
258 s = s.replace(/\[embed\](.*?)\[\/embed\]/gi, _b2h_cb);
\r
267 tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin);
\r