Subversion Repositories oidplus

Rev

Rev 1422 | View as "text/javascript" | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /**
  2.  * Copyright (c) Tiny Technologies, Inc. All rights reserved.
  3.  * Licensed under the LGPL or a commercial license.
  4.  * For LGPL see License.txt in the project root for license information.
  5.  * For commercial licenses see https://www.tiny.cloud/
  6.  *
  7.  * Version: 5.10.9 (2023-11-15)
  8.  */
  9. (function () {
  10.     'use strict';
  11.  
  12.     var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  13.  
  14.     var global = tinymce.util.Tools.resolve('tinymce.util.Tools');
  15.  
  16.     var html2bbcode = function (s) {
  17.       s = global.trim(s);
  18.       var rep = function (re, str) {
  19.         s = s.replace(re, str);
  20.       };
  21.       rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi, '[url=$1]$2[/url]');
  22.       rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi, '[code][color=$1]$2[/color][/code]');
  23.       rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi, '[quote][color=$1]$2[/color][/quote]');
  24.       rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi, '[code][color=$1]$2[/color][/code]');
  25.       rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi, '[quote][color=$1]$2[/color][/quote]');
  26.       rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi, '[color=$1]$2[/color]');
  27.       rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi, '[color=$1]$2[/color]');
  28.       rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi, '[size=$1]$2[/size]');
  29.       rep(/<font>(.*?)<\/font>/gi, '$1');
  30.       rep(/<img.*?src=\"(.*?)\".*?\/>/gi, '[img]$1[/img]');
  31.       rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi, '[code]$1[/code]');
  32.       rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi, '[quote]$1[/quote]');
  33.       rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi, '[code][b]$1[/b][/code]');
  34.       rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi, '[quote][b]$1[/b][/quote]');
  35.       rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi, '[code][i]$1[/i][/code]');
  36.       rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi, '[quote][i]$1[/i][/quote]');
  37.       rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi, '[code][u]$1[/u][/code]');
  38.       rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi, '[quote][u]$1[/u][/quote]');
  39.       rep(/<\/(strong|b)>/gi, '[/b]');
  40.       rep(/<(strong|b)>/gi, '[b]');
  41.       rep(/<\/(em|i)>/gi, '[/i]');
  42.       rep(/<(em|i)>/gi, '[i]');
  43.       rep(/<\/u>/gi, '[/u]');
  44.       rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi, '[u]$1[/u]');
  45.       rep(/<u>/gi, '[u]');
  46.       rep(/<blockquote[^>]*>/gi, '[quote]');
  47.       rep(/<\/blockquote>/gi, '[/quote]');
  48.       rep(/<br \/>/gi, '\n');
  49.       rep(/<br\/>/gi, '\n');
  50.       rep(/<br>/gi, '\n');
  51.       rep(/<p>/gi, '');
  52.       rep(/<\/p>/gi, '\n');
  53.       rep(/&nbsp;|\u00a0/gi, ' ');
  54.       rep(/&quot;/gi, '"');
  55.       rep(/&lt;/gi, '<');
  56.       rep(/&gt;/gi, '>');
  57.       rep(/&amp;/gi, '&');
  58.       return s;
  59.     };
  60.     var bbcode2html = function (s) {
  61.       s = global.trim(s);
  62.       var rep = function (re, str) {
  63.         s = s.replace(re, str);
  64.       };
  65.       rep(/\n/gi, '<br />');
  66.       rep(/\[b\]/gi, '<strong>');
  67.       rep(/\[\/b\]/gi, '</strong>');
  68.       rep(/\[i\]/gi, '<em>');
  69.       rep(/\[\/i\]/gi, '</em>');
  70.       rep(/\[u\]/gi, '<u>');
  71.       rep(/\[\/u\]/gi, '</u>');
  72.       rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi, '<a href="$1">$2</a>');
  73.       rep(/\[url\](.*?)\[\/url\]/gi, '<a href="$1">$1</a>');
  74.       rep(/\[img\](.*?)\[\/img\]/gi, '<img src="$1" />');
  75.       rep(/\[color=(.*?)\](.*?)\[\/color\]/gi, '<font color="$1">$2</font>');
  76.       rep(/\[code\](.*?)\[\/code\]/gi, '<span class="codeStyle">$1</span>&nbsp;');
  77.       rep(/\[quote.*?\](.*?)\[\/quote\]/gi, '<span class="quoteStyle">$1</span>&nbsp;');
  78.       return s;
  79.     };
  80.  
  81.     function Plugin () {
  82.       global$1.add('bbcode', function (editor) {
  83.         editor.on('BeforeSetContent', function (e) {
  84.           e.content = bbcode2html(e.content);
  85.         });
  86.         editor.on('PostProcess', function (e) {
  87.           if (e.set) {
  88.             e.content = bbcode2html(e.content);
  89.           }
  90.           if (e.get) {
  91.             e.content = html2bbcode(e.content);
  92.           }
  93.         });
  94.       });
  95.     }
  96.  
  97.     Plugin();
  98.  
  99. }());
  100.