fckeditor.pl 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Copyright (C) 2005 Alex Schroeder <alex@emacswiki.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. AddModuleDescription('fckeditor.pl', 'Using FCKeditor In Addition To Wiki Markup');
  18. our ($q, @MyRules, @MyInitVariables, $HtmlHeaders);
  19. our ($FCKeditorHeight);
  20. $FCKeditorHeight = 400; # Pixel
  21. push (@MyRules, \&WysiwygRule);
  22. sub WysiwygRule {
  23. if (m/\G(&lt;.*?&gt;)/cg) {
  24. return $1 if substr($1,5,6) eq 'script'
  25. or substr($1,4,6) eq 'script';
  26. return UnquoteHtml($1);
  27. }
  28. return;
  29. }
  30. push (@MyInitVariables, \&WysiwygScript);
  31. sub WysiwygScript {
  32. # cookie is not initialized yet so we cannot use GetParam
  33. if ($q->param('action') eq 'edit') {
  34. $HtmlHeaders = qq{
  35. <script type="text/javascript" src="/FCKeditor/fckeditor.js"></script>
  36. <script type="text/javascript">
  37. window.onload = function()
  38. {
  39. var oFCKeditor = new FCKeditor( 'text' ) ;
  40. oFCKeditor.Height = "$FCKeditorHeight" ;
  41. oFCKeditor.ReplaceTextarea() ;
  42. }
  43. </script>
  44. <style type="text/css">
  45. input[name="Preview"] { display: none; }
  46. </style>
  47. };
  48. }
  49. }
  50. *OldFckImproveDiff = \&ImproveDiff;
  51. *ImproveDiff = \&NewFckImproveDiff;
  52. sub NewFckImproveDiff {
  53. my $old = OldFckImproveDiff(@_);
  54. my $new = '';
  55. my $protected = 0;
  56. # fix diff inserting change boundaries inside tags
  57. $old =~ s!&<strong class="changes">([a-z]+);!</strong>&$1;!g;
  58. $old =~ s!&</strong>([a-z]+);!</strong>&$1;!g;
  59. # unquote named html entities
  60. $old =~ s/\&amp;([a-z]+);/&$1;/g;
  61. foreach my $str (split(/(<strong class="changes">|<\/strong>)/, $old)) {
  62. # Don't remove HTML tags affected by changes.
  63. $protected = 1 if $str eq '<strong class="changes">';
  64. # strip html tags and don't get confused with the < and > created
  65. # by diff!
  66. $str =~ s/\&lt;.*?\&gt;//g unless $protected;
  67. $protected = 0 if $str eq '</strong>';
  68. $new .= $str;
  69. }
  70. return $new;
  71. }