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
12 tinymce.create('tinymce.plugins.BBCodePlugin', {
\r
13 init : function(ed, url) {
\r
14 var t = this, dialect = ed.getParam('bbcode_dialect', 'punbb').toLowerCase();
\r
16 ed.onBeforeSetContent.add(function(ed, o) {
\r
17 o.content = t['_' + dialect + '_bbcode2html'](o.content);
\r
20 ed.onPostProcess.add(function(ed, o) {
\r
22 o.content = t['_' + dialect + '_bbcode2html'](o.content);
\r
25 o.content = t['_' + dialect + '_html2bbcode'](o.content);
\r
29 getInfo : function() {
\r
31 longname : 'BBCode Plugin',
\r
32 author : 'Moxiecode Systems AB',
\r
33 authorurl : 'http://tinymce.moxiecode.com',
\r
34 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',
\r
35 version : tinymce.majorVersion + "." + tinymce.minorVersion
\r
41 // HTML -> BBCode in PunBB dialect
\r
42 _punbb_html2bbcode : function(s) {
\r
43 s = tinymce.trim(s);
\r
45 function rep(re, str) {
\r
46 s = s.replace(re, str);
\r
49 // example: <strong> to [b]
\r
50 rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");
\r
51 rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
\r
52 rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
\r
53 rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
\r
54 rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
\r
55 rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");
\r
56 rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]");
\r
57 rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");
\r
58 rep(/<font>(.*?)<\/font>/gi,"$1");
\r
59 rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
\r
60 rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi,"[code]$1[/code]");
\r
61 rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi,"[quote]$1[/quote]");
\r
62 rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");
\r
63 rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");
\r
64 rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");
\r
65 rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");
\r
66 rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");
\r
67 rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]");
\r
68 rep(/<\/(strong|b)>/gi,"[/b]");
\r
69 rep(/<(strong|b)>/gi,"[b]");
\r
70 rep(/<\/(em|i)>/gi,"[/i]");
\r
71 rep(/<(em|i)>/gi,"[i]");
\r
72 rep(/<\/u>/gi,"[/u]");
\r
73 rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");
\r
75 rep(/<blockquote[^>]*>/gi,"[quote]");
\r
76 rep(/<\/blockquote>/gi,"[/quote]");
\r
77 rep(/<br \/>/gi,"\n");
\r
78 rep(/<br\/>/gi,"\n");
\r
81 rep(/<\/p>/gi,"\n");
\r
82 rep(/ /gi," ");
\r
83 rep(/"/gi,"\"");
\r
91 // BBCode -> HTML from PunBB dialect
\r
92 _punbb_bbcode2html : function(s) {
\r
93 s = tinymce.trim(s);
\r
95 function rep(re, str) {
\r
96 s = s.replace(re, str);
\r
99 // example: [b] to <strong>
\r
100 rep(/\n/gi,"<br />");
\r
101 rep(/\[b\]/gi,"<strong>");
\r
102 rep(/\[\/b\]/gi,"</strong>");
\r
103 rep(/\[i\]/gi,"<em>");
\r
104 rep(/\[\/i\]/gi,"</em>");
\r
105 rep(/\[u\]/gi,"<u>");
\r
106 rep(/\[\/u\]/gi,"</u>");
\r
107 rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");
\r
108 rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
\r
109 rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
\r
110 rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");
\r
111 rep(/\[code\](.*?)\[\/code\]/gi,"<span class=\"codeStyle\">$1</span> ");
\r
112 rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<span class=\"quoteStyle\">$1</span> ");
\r
119 tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin);
\r