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.
master
Joey Hess 2010-10-25 22:37:34 -04:00
parent 38f0bec345
commit 2076ed597c
4 changed files with 50 additions and 24 deletions

View File

@ -29,22 +29,24 @@ sub preprocess (@) {
if (! defined $format || ! defined $text) { if (! defined $format || ! defined $text) {
error(gettext("must specify format and 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}) { elsif (exists $IkiWiki::hooks{htmlize}{$format}) {
return IkiWiki::htmlize($params{page}, $params{destpage}, return IkiWiki::htmlize($params{page}, $params{destpage},
$format, $text); $format, $text);
} }
else { 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)); error(sprintf(gettext("unsupported page format %s"), $format));
} }
} }

View File

@ -10,8 +10,8 @@ sub import {
hook(type => "getsetup", id => "highlight", call => \&getsetup); hook(type => "getsetup", id => "highlight", call => \&getsetup);
hook(type => "checkconfig", id => "highlight", call => \&checkconfig); hook(type => "checkconfig", id => "highlight", call => \&checkconfig);
# this hook is used by the format plugin # this hook is used by the format plugin
hook(type => "htmlizefallback", id => "highlight", call => hook(type => "htmlizeformat", id => "highlight", call =>
\&htmlizefallback); \&htmlizeformat);
} }
sub getsetup () { sub getsetup () {
@ -79,7 +79,7 @@ sub checkconfig () {
} }
} }
sub htmlizefallback { sub htmlizeformat {
my $format=lc shift; my $format=lc shift;
my $langfile=ext2langfile($format); my $langfile=ext2langfile($format);

View File

@ -17,6 +17,7 @@ sub import {
hook(type => "getsetup", id => "txt", call => \&getsetup); hook(type => "getsetup", id => "txt", call => \&getsetup);
hook(type => "filter", id => "txt", call => \&filter); hook(type => "filter", id => "txt", call => \&filter);
hook(type => "htmlize", id => "txt", call => \&htmlize); hook(type => "htmlize", id => "txt", call => \&htmlize);
hook(type => "htmlizeformat", id => "txt", call => \&htmlizeformat);
eval q{use URI::Find}; eval q{use URI::Find};
if (! $@) { if (! $@) {
@ -46,25 +47,42 @@ sub filter (@) {
will_render($params{page}, 'robots.txt'); will_render($params{page}, 'robots.txt');
writefile('robots.txt', $config{destdir}, $content); writefile('robots.txt', $config{destdir}, $content);
} }
return txt2html($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 $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 # We need this to register the .txt file extension
sub htmlize (@) { sub htmlize (@) {
my %params=@_; my %params=@_;
return $params{content}; return $params{content};
} }
sub htmlizeformat ($$) {
my $format=shift;
my $content=shift;
if ($format eq 'txt') {
return txt2html($content);
}
else {
return;
}
}
1 1

6
debian/changelog vendored
View 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 ikiwiki (3.20101023) unstable; urgency=low
* Fix typo that broke anonymous git push. * Fix typo that broke anonymous git push.