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
51 // example: <strong> to [b]
\r
52 rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");
\r
53 rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");
\r
54 rep(/<font>(.*?)<\/font>/gi,"$1");
\r
55 rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
\r
56 rep(/<code>(.*?)<\/code>/gi,"[code]$1[/code]");
\r
57 rep(/<\/(strong|b)>/gi,"[/b]");
\r
58 rep(/<(strong|b)>/gi,"[b]");
\r
59 rep(/<\/(em|i)>/gi,"[/i]");
\r
60 rep(/<(em|i)>/gi,"[i]");
\r
61 rep(/<\/u>/gi,"[/u]");
\r
62 rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");
\r
64 rep(/<blockquote[^>]*>/gi,"[quote]");
\r
65 rep(/<\/blockquote>/gi,"[/quote]");
\r
66 rep(/<br \/>/gi,"\n");
\r
67 rep(/<br\/>/gi,"\n");
\r
70 rep(/<\/p>/gi,"\n");
\r
71 rep(/ /gi," ");
\r
72 rep(/"/gi,"\"");
\r
80 // BBCode -> HTML from DFRN dialect
\r
81 _dfrn_bbcode2html : function(s) {
\r
82 s = tinymce.trim(s);
\r
84 function rep(re, str) {
\r
85 s = s.replace(re, str);
\r
88 // example: [b] to <strong>
\r
89 rep(/\n/gi,"<br />");
\r
90 rep(/\[b\]/gi,"<strong>");
\r
91 rep(/\[\/b\]/gi,"</strong>");
\r
92 rep(/\[i\]/gi,"<em>");
\r
93 rep(/\[\/i\]/gi,"</em>");
\r
94 rep(/\[u\]/gi,"<u>");
\r
95 rep(/\[\/u\]/gi,"</u>");
\r
96 rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");
\r
97 rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
\r
98 rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
\r
99 rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");
\r
100 rep(/\[code\](.*?)\[\/code\]/gi,"<code>$1</code>");
\r
101 rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<blockquote>$1</blockquote>");
\r
108 tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin);
\r