wiki.pl: Port some fixes from upstream
[Orgmuse.git] / modules / fckeditor.pl
blob00a17b223489195d1bc7817c560fcf9e0ea3a21e
1 # Copyright (C) 2005 Alex Schroeder <alex@emacswiki.org>
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.
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.
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,
19 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/fckeditor.pl">fckeditor.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Using_FCKeditor_In_Addition_To_Wiki_Markup">Using FCKeditor In Addition To Wiki Markup</a></p>';
21 use vars qw($FCKeditorHeight);
23 $FCKeditorHeight = 400; # Pixel
25 push (@MyRules, \&WysiwygRule);
27 sub WysiwygRule {
28 if (m/\G(&lt;.*?&gt;)/gc) {
29 return $1 if substr($1,5,6) eq 'script'
30 or substr($1,4,6) eq 'script';
31 return UnquoteHtml($1);
33 return undef;
36 push (@MyInitVariables, \&WysiwygScript);
38 sub WysiwygScript {
39 # cookie is not initialized yet so we cannot use GetParam
40 if ($q->param('action') eq 'edit') {
41 $HtmlHeaders = qq{
42 <script type="text/javascript" src="/FCKeditor/fckeditor.js"></script>
43 <script type="text/javascript">
44 window.onload = function()
46 var oFCKeditor = new FCKeditor( 'text' ) ;
47 oFCKeditor.Height = "$FCKeditorHeight" ;
48 oFCKeditor.ReplaceTextarea() ;
50 </script>
51 <style type="text/css">
52 input[name="Preview"] { display: none; }
53 </style>
58 *OldFckImproveDiff = *ImproveDiff;
59 *ImproveDiff = *NewFckImproveDiff;
61 sub NewFckImproveDiff {
62 my $old = OldFckImproveDiff(@_);
63 my $new = '';
64 my $protected = 0;
65 # fix diff inserting change boundaries inside tags
66 $old =~ s!&<strong class="changes">([a-z]+);!</strong>&$1;!g;
67 $old =~ s!&</strong>([a-z]+);!</strong>&$1;!g;
68 # unquote named html entities
69 $old =~ s/\&amp;([a-z]+);/&$1;/g;
70 foreach my $str (split(/(<strong class="changes">|<\/strong>)/, $old)) {
71 # Don't remove HTML tags affected by changes.
72 $protected = 1 if $str eq '<strong class="changes">';
73 # strip html tags and don't get confused with the < and > created
74 # by diff!
75 $str =~ s/\&lt;.*?\&gt;//g unless $protected;
76 $protected = 0 if $str eq '</strong>';
77 $new .= $str;
79 return $new;