1
var TinyMCE_BBCodePlugin = {
4
longname : 'BBCode Plugin',
5
author : 'Moxiecode Systems AB',
6
authorurl : 'http://tinymce.moxiecode.com',
7
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',
8
version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
12
cleanup : function(type, content) {
13
var dialect = tinyMCE.getParam('bbcode_dialect', 'punbb').toLowerCase();
16
case "insert_to_editor":
17
content = this['_' + dialect + '_bbcode2html'](content);
20
case "get_from_editor":
21
content = this['_' + dialect + '_html2bbcode'](content);
30
// HTML -> BBCode in PunBB dialect
31
_punbb_html2bbcode : function(s) {
34
function rep(re, str) {
35
s = s.replace(re, str);
38
// example: <strong> to [b]
39
rep(/<a href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url]$1[/url]");
40
rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
41
rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
42
rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
43
rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
44
rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]");
45
rep(/<font>(.*?)<\/font>/gi,"$1");
46
rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
47
rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi,"[code]$1[/code]");
48
rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi,"[quote]$1[/quote]");
49
rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");
50
rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");
51
rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");
52
rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");
53
rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");
54
rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]");
55
rep(/<\/(strong|b)>/gi,"[/b]");
56
rep(/<(strong|b)>/gi,"[b]");
57
rep(/<\/(em|i)>/gi,"[/i]");
58
rep(/<(em|i)>/gi,"[i]");
59
rep(/<\/u>/gi,"[/u]");
61
rep(/<br \/>/gi,"\n");
71
rep(/&undefined;/gi,"'"); // quickfix
76
// BBCode -> HTML from PunBB dialect
77
_punbb_bbcode2html : function(s) {
80
function rep(re, str) {
81
s = s.replace(re, str);
84
// example: [b] to <strong>
86
rep(/\[b\]/gi,"<strong>");
87
rep(/\[\/b\]/gi,"</strong>");
88
rep(/\[i\]/gi,"<em>");
89
rep(/\[\/i\]/gi,"</em>");
91
rep(/\[\/u\]/gi,"</u>");
92
rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
93
rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
94
rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");
95
rep(/\[code\](.*?)\[\/code\]/gi,"<span class=\"codeStyle\">$1</span> ");
96
rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<span class=\"quoteStyle\">$1</span> ");
102
tinyMCE.addPlugin("bbcode", TinyMCE_BBCodePlugin);