diff options
author | Joey Hess <joey@kitenet.net> | 2010-10-25 22:37:34 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-10-25 22:37:34 -0400 |
commit | 2076ed597c02bfede9063c3d40f4b855d4e8f8b8 (patch) | |
tree | fdff58f7baddd1ab9d5fe946825e15dc516b16cf /IkiWiki | |
parent | 38f0bec34560d2258a2d690676987b12ab184490 (diff) | |
download | ikiwiki-2076ed597c02bfede9063c3d40f4b855d4e8f8b8.tar ikiwiki-2076ed597c02bfede9063c3d40f4b855d4e8f8b8.tar.gz |
txt: Fix display when used inside a format directive.
txt's use of a format hook can't work in that case, so it needs to use a
htmlizeformat hook in this case to handle wrapping the text in pre tags.
Diffstat (limited to 'IkiWiki')
-rw-r--r-- | IkiWiki/Plugin/format.pm | 24 | ||||
-rw-r--r-- | IkiWiki/Plugin/highlight.pm | 6 | ||||
-rw-r--r-- | IkiWiki/Plugin/txt.pm | 38 |
3 files changed, 44 insertions, 24 deletions
diff --git a/IkiWiki/Plugin/format.pm b/IkiWiki/Plugin/format.pm index d54e71131..b596bc0a1 100644 --- a/IkiWiki/Plugin/format.pm +++ b/IkiWiki/Plugin/format.pm @@ -29,22 +29,24 @@ sub preprocess (@) { if (! defined $format || ! defined $text) { error(gettext("must specify format and text")); } + + # Other plugins can register htmlizeformat hooks to add support + # for page types not suitable for htmlize, or that need special + # processing when included via format. Try them until one succeeds. + my $ret; + IkiWiki::run_hooks(htmlizeformat => sub { + $ret=shift->($format, $text) + unless defined $ret; + }); + + if (defined $ret) { + return $ret; + } elsif (exists $IkiWiki::hooks{htmlize}{$format}) { return IkiWiki::htmlize($params{page}, $params{destpage}, $format, $text); } else { - # Other plugins can register htmlizefallback - # hooks to add support for page types - # not suitable for htmlize. Try them until - # one succeeds. - my $ret; - IkiWiki::run_hooks(htmlizefallback => sub { - $ret=shift->($format, $text) - unless defined $ret; - }); - return $ret if defined $ret; - error(sprintf(gettext("unsupported page format %s"), $format)); } } diff --git a/IkiWiki/Plugin/highlight.pm b/IkiWiki/Plugin/highlight.pm index d4ade0a7b..5674f0b4a 100644 --- a/IkiWiki/Plugin/highlight.pm +++ b/IkiWiki/Plugin/highlight.pm @@ -10,8 +10,8 @@ sub import { hook(type => "getsetup", id => "highlight", call => \&getsetup); hook(type => "checkconfig", id => "highlight", call => \&checkconfig); # this hook is used by the format plugin - hook(type => "htmlizefallback", id => "highlight", call => - \&htmlizefallback); + hook(type => "htmlizeformat", id => "highlight", call => + \&htmlizeformat); } sub getsetup () { @@ -79,7 +79,7 @@ sub checkconfig () { } } -sub htmlizefallback { +sub htmlizeformat { my $format=lc shift; my $langfile=ext2langfile($format); diff --git a/IkiWiki/Plugin/txt.pm b/IkiWiki/Plugin/txt.pm index 0d9a0b35b..fcfb68be9 100644 --- a/IkiWiki/Plugin/txt.pm +++ b/IkiWiki/Plugin/txt.pm @@ -17,6 +17,7 @@ sub import { hook(type => "getsetup", id => "txt", call => \&getsetup); hook(type => "filter", id => "txt", call => \&filter); hook(type => "htmlize", id => "txt", call => \&htmlize); + hook(type => "htmlizeformat", id => "txt", call => \&htmlizeformat); eval q{use URI::Find}; if (! $@) { @@ -46,25 +47,42 @@ sub filter (@) { will_render($params{page}, 'robots.txt'); writefile('robots.txt', $config{destdir}, $content); } - - encode_entities($content, "<>&"); - if ($findurl) { - my $finder = URI::Find->new(sub { - my ($uri, $orig_uri) = @_; - return qq|<a href="$uri">$orig_uri</a>|; - }); - $finder->find(\$content); - } - $content = "<pre>" . $content . "</pre>"; + return txt2html($content); } return $content; } +sub txt2html ($) { + my $content=shift; + + encode_entities($content, "<>&"); + if ($findurl) { + my $finder = URI::Find->new(sub { + my ($uri, $orig_uri) = @_; + return qq|<a href="$uri">$orig_uri</a>|; + }); + $finder->find(\$content); + } + return "<pre>" . $content . "</pre>"; +} + # We need this to register the .txt file extension sub htmlize (@) { my %params=@_; return $params{content}; } +sub htmlizeformat ($$) { + my $format=shift; + my $content=shift; + + if ($format eq 'txt') { + return txt2html($content); + } + else { + return; + } +} + 1 |