2 * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
\r
5 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
\r
9 tinymce.create('tinymce.plugins.BBCodePlugin', {
\r
10 init : function(ed, url) {
\r
11 var t = this, dialect = ed.getParam('bbcode_dialect', 'punbb').toLowerCase();
\r
13 ed.onBeforeSetContent.add(function(ed, o) {
\r
14 o.content = t['_' + dialect + '_bbcode2html'](o.content);
\r
17 ed.onPostProcess.add(function(ed, o) {
\r
19 o.content = t['_' + dialect + '_bbcode2html'](o.content);
\r
22 o.content = t['_' + dialect + '_html2bbcode'](o.content);
\r
26 getInfo : function() {
\r
28 longname : 'BBCode Plugin',
\r
29 author : 'Moxiecode Systems AB',
\r
30 authorurl : 'http://tinymce.moxiecode.com',
\r
31 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',
\r
32 version : tinymce.majorVersion + "." + tinymce.minorVersion
\r
38 // HTML -> BBCode in PunBB dialect
\r
39 _punbb_html2bbcode : function(s) {
\r
40 s = tinymce.trim(s);
\r
42 function rep(re, str) {
\r
43 s = s.replace(re, str);
\r
46 // example: <strong> to [b]
\r
47 rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");
\r
48 rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
\r
49 rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
\r
50 rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
\r
51 rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
\r
52 rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");
\r
53 rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]");
\r
54 rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");
\r
55 rep(/<font>(.*?)<\/font>/gi,"$1");
\r
56 rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
\r
57 rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi,"[code]$1[/code]");
\r
58 rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi,"[quote]$1[/quote]");
\r
59 rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");
\r
60 rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");
\r
61 rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");
\r
62 rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");
\r
63 rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");
\r
64 rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]");
\r
65 rep(/<\/(strong|b)>/gi,"[/b]");
\r
66 rep(/<(strong|b)>/gi,"[b]");
\r
67 rep(/<\/(em|i)>/gi,"[/i]");
\r
68 rep(/<(em|i)>/gi,"[i]");
\r
69 rep(/<\/u>/gi,"[/u]");
\r
70 rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");
\r
72 rep(/<blockquote[^>]*>/gi,"[quote]");
\r
73 rep(/<\/blockquote>/gi,"[/quote]");
\r
74 rep(/<br \/>/gi,"\n");
\r
75 rep(/<br\/>/gi,"\n");
\r
78 rep(/<\/p>/gi,"\n");
\r
79 rep(/ /gi," ");
\r
80 rep(/"/gi,"\"");
\r
88 // BBCode -> HTML from PunBB dialect
\r
89 _punbb_bbcode2html : function(s) {
\r
90 s = tinymce.trim(s);
\r
92 function rep(re, str) {
\r
93 s = s.replace(re, str);
\r
96 // example: [b] to <strong>
\r
97 rep(/\n/gi,"<br />");
\r
98 rep(/\[b\]/gi,"<strong>");
\r
99 rep(/\[\/b\]/gi,"</strong>");
\r
100 rep(/\[i\]/gi,"<em>");
\r
101 rep(/\[\/i\]/gi,"</em>");
\r
102 rep(/\[u\]/gi,"<u>");
\r
103 rep(/\[\/u\]/gi,"</u>");
\r
104 rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");
\r
105 rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
\r
106 rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
\r
107 rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");
\r
108 rep(/\[code\](.*?)\[\/code\]/gi,"<span class=\"codeStyle\">$1</span> ");
\r
109 rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<span class=\"quoteStyle\">$1</span> ");
\r
116 tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin);
\r