fckeditor.pl 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 2 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, write to the
  15. # Free Software Foundation, Inc.
  16. # 59 Temple Place, Suite 330
  17. # Boston, MA 02111-1307 USA,
  18. use strict;
  19. use v5.10;
  20. AddModuleDescription('fckeditor.pl', 'Using FCKeditor In Addition To Wiki Markup');
  21. our ($q, @MyRules, @MyInitVariables, $HtmlHeaders);
  22. our ($FCKeditorHeight);
  23. $FCKeditorHeight = 400; # Pixel
  24. push (@MyRules, \&WysiwygRule);
  25. sub WysiwygRule {
  26. if (m/\G(&lt;.*?&gt;)/cg) {
  27. return $1 if substr($1,5,6) eq 'script'
  28. or substr($1,4,6) eq 'script';
  29. return UnquoteHtml($1);
  30. }
  31. return;
  32. }
  33. push (@MyInitVariables, \&WysiwygScript);
  34. sub WysiwygScript {
  35. # cookie is not initialized yet so we cannot use GetParam
  36. if ($q->param('action') eq 'edit') {
  37. $HtmlHeaders = qq{
  38. <script type="text/javascript" src="/FCKeditor/fckeditor.js"></script>
  39. <script type="text/javascript">
  40. window.onload = function()
  41. {
  42. var oFCKeditor = new FCKeditor( 'text' ) ;
  43. oFCKeditor.Height = "$FCKeditorHeight" ;
  44. oFCKeditor.ReplaceTextarea() ;
  45. }
  46. </script>
  47. <style type="text/css">
  48. input[name="Preview"] { display: none; }
  49. </style>
  50. };
  51. }
  52. }
  53. *OldFckImproveDiff = \&ImproveDiff;
  54. *ImproveDiff = \&NewFckImproveDiff;
  55. sub NewFckImproveDiff {
  56. my $old = OldFckImproveDiff(@_);
  57. my $new = '';
  58. my $protected = 0;
  59. # fix diff inserting change boundaries inside tags
  60. $old =~ s!&<strong class="changes">([a-z]+);!</strong>&$1;!g;
  61. $old =~ s!&</strong>([a-z]+);!</strong>&$1;!g;
  62. # unquote named html entities
  63. $old =~ s/\&amp;([a-z]+);/&$1;/g;
  64. foreach my $str (split(/(<strong class="changes">|<\/strong>)/, $old)) {
  65. # Don't remove HTML tags affected by changes.
  66. $protected = 1 if $str eq '<strong class="changes">';
  67. # strip html tags and don't get confused with the < and > created
  68. # by diff!
  69. $str =~ s/\&lt;.*?\&gt;//g unless $protected;
  70. $protected = 0 if $str eq '</strong>';
  71. $new .= $str;
  72. }
  73. return $new;
  74. }