PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/editors/tiny_mce_3_4_3_1/plugins/bbcode/editor_plugin_src.js

#
JavaScript | 120 lines | 90 code | 15 blank | 15 comment | 2 complexity | 842450703b915245adb53df7d478ea5a MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. /**
  2. * editor_plugin_src.js
  3. *
  4. * Copyright 2009, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://tinymce.moxiecode.com/license
  8. * Contributing: http://tinymce.moxiecode.com/contributing
  9. */
  10. (function() {
  11. tinymce.create('tinymce.plugins.BBCodePlugin', {
  12. init : function(ed, url) {
  13. var t = this, dialect = ed.getParam('bbcode_dialect', 'punbb').toLowerCase();
  14. ed.onBeforeSetContent.add(function(ed, o) {
  15. o.content = t['_' + dialect + '_bbcode2html'](o.content);
  16. });
  17. ed.onPostProcess.add(function(ed, o) {
  18. if (o.set)
  19. o.content = t['_' + dialect + '_bbcode2html'](o.content);
  20. if (o.get)
  21. o.content = t['_' + dialect + '_html2bbcode'](o.content);
  22. });
  23. },
  24. getInfo : function() {
  25. return {
  26. longname : 'BBCode Plugin',
  27. author : 'Moxiecode Systems AB',
  28. authorurl : 'http://tinymce.moxiecode.com',
  29. infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',
  30. version : tinymce.majorVersion + "." + tinymce.minorVersion
  31. };
  32. },
  33. // Private methods
  34. // HTML -> BBCode in PunBB dialect
  35. _punbb_html2bbcode : function(s) {
  36. s = tinymce.trim(s);
  37. function rep(re, str) {
  38. s = s.replace(re, str);
  39. };
  40. // example: <strong> to [b]
  41. rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");
  42. rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
  43. rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
  44. rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
  45. rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
  46. rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");
  47. rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]");
  48. rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");
  49. rep(/<font>(.*?)<\/font>/gi,"$1");
  50. rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
  51. rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi,"[code]$1[/code]");
  52. rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi,"[quote]$1[/quote]");
  53. rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");
  54. rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");
  55. rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");
  56. rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");
  57. rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");
  58. rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]");
  59. rep(/<\/(strong|b)>/gi,"[/b]");
  60. rep(/<(strong|b)>/gi,"[b]");
  61. rep(/<\/(em|i)>/gi,"[/i]");
  62. rep(/<(em|i)>/gi,"[i]");
  63. rep(/<\/u>/gi,"[/u]");
  64. rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");
  65. rep(/<u>/gi,"[u]");
  66. rep(/<blockquote[^>]*>/gi,"[quote]");
  67. rep(/<\/blockquote>/gi,"[/quote]");
  68. rep(/<br \/>/gi,"\n");
  69. rep(/<br\/>/gi,"\n");
  70. rep(/<br>/gi,"\n");
  71. rep(/<p>/gi,"");
  72. rep(/<\/p>/gi,"\n");
  73. rep(/&nbsp;|\u00a0/gi," ");
  74. rep(/&quot;/gi,"\"");
  75. rep(/&lt;/gi,"<");
  76. rep(/&gt;/gi,">");
  77. rep(/&amp;/gi,"&");
  78. return s;
  79. },
  80. // BBCode -> HTML from PunBB dialect
  81. _punbb_bbcode2html : function(s) {
  82. s = tinymce.trim(s);
  83. function rep(re, str) {
  84. s = s.replace(re, str);
  85. };
  86. // example: [b] to <strong>
  87. rep(/\n/gi,"<br />");
  88. rep(/\[b\]/gi,"<strong>");
  89. rep(/\[\/b\]/gi,"</strong>");
  90. rep(/\[i\]/gi,"<em>");
  91. rep(/\[\/i\]/gi,"</em>");
  92. rep(/\[u\]/gi,"<u>");
  93. rep(/\[\/u\]/gi,"</u>");
  94. rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");
  95. rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
  96. rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
  97. rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");
  98. rep(/\[code\](.*?)\[\/code\]/gi,"<span class=\"codeStyle\">$1</span>&nbsp;");
  99. rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<span class=\"quoteStyle\">$1</span>&nbsp;");
  100. return s;
  101. }
  102. });
  103. // Register plugin
  104. tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin);
  105. })();