diff options
author | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2006-07-26 21:54:44 +0000 |
---|---|---|
committer | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2006-07-26 21:54:44 +0000 |
commit | d9c118dbf1753abcbf081f532aecfe8cb6ce7de7 (patch) | |
tree | 4760a558c0ab1f7cbd4d44454c3f36cd072fe78c /IkiWiki | |
parent | 061afedb261f67731acac341811f4b086da2ab92 (diff) |
* Run page through any relevant filters when generating a page preview.
* Noticed a bug in the wikitext markup plugin -- it made CamelCase links the
default throughout the wiki, not only on wikitext pages. Decided to call
this a feature, and split the camelcase support out into a separate plugin
that is independant of wikitext.
Diffstat (limited to 'IkiWiki')
-rw-r--r-- | IkiWiki/CGI.pm | 2 | ||||
-rw-r--r-- | IkiWiki/Plugin/camelcase.pm | 22 | ||||
-rw-r--r-- | IkiWiki/Plugin/wikitext.pm | 11 | ||||
-rw-r--r-- | IkiWiki/Render.pm | 25 |
4 files changed, 40 insertions, 20 deletions
diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index 759a49b7d..7360ca998 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -417,7 +417,7 @@ sub cgi_editpage ($$) { #{{{ $form->field(name => "comments", value => $comments, force => 1); $form->tmpl_param("page_preview", - htmlize($type, linkify($page, $page, $content))); + htmlize($type, linkify($page, $page, filter($page, $content)))); } else { $form->tmpl_param("page_preview", ""); diff --git a/IkiWiki/Plugin/camelcase.pm b/IkiWiki/Plugin/camelcase.pm new file mode 100644 index 000000000..0934b27c2 --- /dev/null +++ b/IkiWiki/Plugin/camelcase.pm @@ -0,0 +1,22 @@ +#!/usr/bin/perl +# CamelCase links +package IkiWiki::Plugin::camelcase; + +use warnings; +use strict; + +sub import { #{{{ + IkiWiki::hook(type => "filter", id => "camelcase", call => \&filter); +} # }}} + +sub filter (@) { #{{{ + my %params=@_; + + # Make CamelCase links work by promoting them to fullfledged + # WikiLinks. This regexp is based on the one in Text::WikiFormat. + $params{content}=~s#(?<![["/>=])\b((?:[A-Z][a-z0-9]\w*){2,})#[[$1]]#g; + + return $params{content}; +} #}}} + +1 diff --git a/IkiWiki/Plugin/wikitext.pm b/IkiWiki/Plugin/wikitext.pm index 310b86724..8b8cbe75e 100644 --- a/IkiWiki/Plugin/wikitext.pm +++ b/IkiWiki/Plugin/wikitext.pm @@ -7,20 +7,9 @@ use strict; use Text::WikiFormat; sub import { #{{{ - IkiWiki::hook(type => "filter", id => "wiki", call => \&filter); IkiWiki::hook(type => "htmlize", id => "wiki", call => \&htmlize); } # }}} -sub filter (@) { #{{{ - my %params=@_; - - # Make CamelCase links work by promoting them to fullfledged - # WikiLinks. This regexp is based on the one in Text::WikiFormat. - $params{content}=~s#(?<![["/>=])\b((?:[A-Z][a-z0-9]\w*){2,})#[[$1]]#g; - - return $params{content}; -} #}}} - sub htmlize ($) { #{{{ my $content = shift; diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 6d5ea9ee5..e5a1679f8 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -250,6 +250,22 @@ sub findlinks ($$) { #{{{ } } #}}} +sub filter ($$) { + my $page=shift; + my $content=shift; + + if (exists $hooks{filter}) { + foreach my $id (keys %{$hooks{filter}}) { + $content=$hooks{filter}{$id}{call}->( + page => $page, + content => $content + ); + } + } + + return $content; +} + sub render ($) { #{{{ my $file=shift; @@ -260,14 +276,7 @@ sub render ($) { #{{{ my $page=pagename($file); delete $depends{$page}; - if (exists $hooks{filter}) { - foreach my $id (keys %{$hooks{filter}}) { - $content=$hooks{filter}{$id}{call}->( - page => $page, - content => $content - ); - } - } + $content=filter($page, $content); $links{$page}=[findlinks($page, $content)]; |