2 * Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
\r
6 tinymce.create('tinymce.plugins.BBCodePlugin', {
\r
7 init : function(ed, url) {
\r
8 var t = this, dialect = ed.getParam('bbcode_dialect', 'punbb').toLowerCase();
\r
10 ed.onBeforeSetContent.add(function(ed, o) {
\r
11 o.content = t['_' + dialect + '_bbcode2html'](o.content);
\r
14 ed.onPostProcess.add(function(ed, o) {
\r
16 o.content = t['_' + dialect + '_bbcode2html'](o.content);
\r
19 o.content = t['_' + dialect + '_html2bbcode'](o.content);
\r
23 getInfo : function() {
\r
25 longname : 'BBCode Plugin',
\r
26 author : 'Moxiecode Systems AB',
\r
27 authorurl : 'http://tinymce.moxiecode.com',
\r
28 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',
\r
29 version : tinymce.majorVersion + "." + tinymce.minorVersion
\r
35 // HTML -> BBCode in PunBB dialect
\r
36 _punbb_html2bbcode : function(s) {
\r
37 s = tinymce.trim(s);
\r
39 function rep(re, str) {
\r
40 s = s.replace(re, str);
\r
43 // example: <strong> to [b]
\r
44 rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");
\r
45 rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
\r
46 rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
\r
47 rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
\r
48 rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
\r
49 rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");
\r
50 rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]");
\r
51 rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");
\r
52 rep(/<font>(.*?)<\/font>/gi,"$1");
\r
53 rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
\r
54 rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi,"[code]$1[/code]");
\r
55 rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi,"[quote]$1[/quote]");
\r
56 rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");
\r
57 rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");
\r
58 rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");
\r
59 rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");
\r
60 rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");
\r
61 rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]");
\r
62 rep(/<\/(strong|b)>/gi,"[/b]");
\r
63 rep(/<(strong|b)>/gi,"[b]");
\r
64 rep(/<\/(em|i)>/gi,"[/i]");
\r
65 rep(/<(em|i)>/gi,"[i]");
\r
66 rep(/<\/u>/gi,"[/u]");
\r
67 rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");
\r
69 rep(/<blockquote[^>]*>/gi,"[quote]");
\r
70 rep(/<\/blockquote>/gi,"[/quote]");
\r
71 rep(/<br \/>/gi,"\n");
\r
72 rep(/<br\/>/gi,"\n");
\r
75 rep(/<\/p>/gi,"\n");
\r
76 rep(/ /gi," ");
\r
77 rep(/"/gi,"\"");
\r
85 // BBCode -> HTML from PunBB dialect
\r
86 _punbb_bbcode2html : function(s) {
\r
87 s = tinymce.trim(s);
\r
89 function rep(re, str) {
\r
90 s = s.replace(re, str);
\r
93 // example: [b] to <strong>
\r
94 rep(/\n/gi,"<br />");
\r
95 rep(/\[b\]/gi,"<strong>");
\r
96 rep(/\[\/b\]/gi,"</strong>");
\r
97 rep(/\[i\]/gi,"<em>");
\r
98 rep(/\[\/i\]/gi,"</em>");
\r
99 rep(/\[u\]/gi,"<u>");
\r
100 rep(/\[\/u\]/gi,"</u>");
\r
101 rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");
\r
102 rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
\r
103 rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
\r
104 rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");
\r
105 rep(/\[code\](.*?)\[\/code\]/gi,"<span class=\"codeStyle\">$1</span> ");
\r
106 rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<span class=\"quoteStyle\">$1</span> ");
\r
113 tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin);
\r