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
48 s = s.replace(re, str);
\r
55 function _h2b_cb(match) {
56 text = bin2hex(match);
57 function s_h2b(data) {
61 url: 'oembed/h2b?text=' + text,
68 s = s.replace(/<span class=\"oembed(.*?)<\/span>/gi, _h2b_cb);
72 // example: <strong> to [b]
\r
73 rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");
\r
74 rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");
\r
75 rep(/<span style=\"color:(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");
\r
76 rep(/<font>(.*?)<\/font>/gi,"$1");
\r
77 rep(/<img.*?width=\"(.*?)\".*?height=\"(.*?)\".*?src=\"(.*?)\".*?\/>/gi,"[img=$1x$2]$3[/img]");
\r
78 rep(/<img.*?height=\"(.*?)\".*?width=\"(.*?)\".*?src=\"(.*?)\".*?\/>/gi,"[img=$2x$1]$3[/img]");
\r
79 rep(/<img.*?src=\"(.*?)\".*?height=\"(.*?)\".*?width=\"(.*?)\".*?\/>/gi,"[img=$3x$2]$1[/img]");
\r
80 rep(/<img.*?src=\"(.*?)\".*?width=\"(.*?)\".*?height=\"(.*?)\".*?\/>/gi,"[img=$2x$3]$1[/img]");
\r
81 rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
\r
82 rep(/<code>(.*?)<\/code>/gi,"[code]$1[/code]");
\r
83 rep(/<\/(strong|b)>/gi,"[/b]");
\r
84 rep(/<(strong|b)>/gi,"[b]");
\r
85 rep(/<\/(em|i)>/gi,"[/i]");
\r
86 rep(/<(em|i)>/gi,"[i]");
\r
87 rep(/<\/u>/gi,"[/u]");
\r
88 rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");
\r
90 rep(/<blockquote[^>]*>/gi,"[quote]");
\r
91 rep(/<\/blockquote>/gi,"[/quote]");
\r
92 rep(/<br \/>/gi,"\n\n");
\r
93 rep(/<br\/>/gi,"\n\n");
\r
96 rep(/<\/p>/gi,"\n");
\r
97 rep(/ /gi," ");
\r
98 rep(/"/gi,"\"");
\r
101 rep(/&/gi,"&");
\r
106 // BBCode -> HTML from DFRN dialect
\r
107 _dfrn_bbcode2html : function(s) {
\r
108 s = tinymce.trim(s);
\r
110 function rep(re, str) {
\r
111 s = s.replace(re, str);
\r
114 // example: [b] to <strong>
\r
115 rep(/\n/gi,"<br />");
\r
116 rep(/\[b\]/gi,"<strong>");
\r
117 rep(/\[\/b\]/gi,"</strong>");
\r
118 rep(/\[i\]/gi,"<em>");
\r
119 rep(/\[\/i\]/gi,"</em>");
\r
120 rep(/\[u\]/gi,"<u>");
\r
121 rep(/\[\/u\]/gi,"</u>");
\r
122 rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");
\r
123 rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
\r
124 rep(/\[img=(.*?)x(.*?)\](.*?)\[\/img\]/gi,"<img width=\"$1\" height=\"$2\" src=\"$3\" />");
\r
125 rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
\r
126 rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<span style=\"color: $1;\">$2</span>");
\r
127 rep(/\[size=(.*?)\](.*?)\[\/size\]/gi,"<span style=\"font-size: $1;\">$2</span>");
\r
128 rep(/\[code\](.*?)\[\/code\]/gi,"<code>$1</code>");
\r
129 rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<blockquote>$1</blockquote>");
\r
132 function _b2h_cb(match, url) {
134 function s_b2h(data) {
138 url: 'oembed/b2h?url=' + url,
145 s = s.replace(/\[embed\](.*?)\[\/embed\]/gi, _b2h_cb);
154 tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin);
\r