txt: Fix display when used inside a format directive.
authorJoey Hess <joey@kitenet.net>
Tue, 26 Oct 2010 02:37:34 +0000 (22:37 -0400)
committerJoey Hess <joey@kitenet.net>
Tue, 26 Oct 2010 02:37:34 +0000 (22:37 -0400)
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.

IkiWiki/Plugin/format.pm
IkiWiki/Plugin/highlight.pm
IkiWiki/Plugin/txt.pm
debian/changelog

index d54e7113198093a2a939315077f7f99d34c529a8..b596bc0a10343b91cf7287f5b5fa06a81084b055 100644 (file)
@@ -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));
        }
 }
index d4ade0a7b3f788c71472c82b1e359b5572731d74..5674f0b4aa150557fbb75e76e208a284dd145288 100644 (file)
@@ -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);
 
index 0d9a0b35bd8abf6be895c4d1ce85f64a6077ded1..fcfb68be90891fca4a46ef512b43548362ffb9e1 100644 (file)
@@ -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
index b304e4b8645ffb33017784913787733e4f430bf7..2857ec482e3f593ef6f76809e3354a29f78ca9ab 100644 (file)
@@ -1,3 +1,9 @@
+ikiwiki (3.20101024) UNRELEASED; urgency=low
+
+  * txt: Fix display when used inside a format directive.
+
+ -- Joey Hess <joeyh@debian.org>  Mon, 25 Oct 2010 22:30:29 -0400
+
 ikiwiki (3.20101023) unstable; urgency=low
 
   * Fix typo that broke anonymous git push.