X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/140658bc51338b8d1c74382bbf374ad77f07c269..e71ca35ac620d9cdd331c3b60971f8d67d7c1044:/IkiWiki/Render.pm?ds=sidebyside diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 886a30f6b..3be8e1c53 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -25,6 +25,8 @@ sub htmlize ($$) { #{{{ my $content=shift; if (! $INC{"/usr/bin/markdown"}) { + # Note: a proper perl module is available in Debian + # for markdown, but not upstream yet. no warnings 'once'; $blosxom::version="is a proper perl module too much to ask?"; use warnings 'all'; @@ -33,9 +35,12 @@ sub htmlize ($$) { #{{{ } if ($type eq '.mdwn') { - # Markdown does character based stuff that does not work - # well with utf-8 strings. - $content=Encode::decode_utf8(Markdown::Markdown(Encode::encode_utf8($content))); + # Workaround for perl bug (#376329) + $content=Encode::encode_utf8($content); + $content=Encode::encode_utf8($content); + $content=Markdown::Markdown($content); + $content=Encode::decode_utf8($content); + $content=Encode::decode_utf8($content); } else { error("htmlization of $type not supported"); @@ -95,9 +100,10 @@ sub parentlinks ($) { #{{{ return @ret; } #}}} -sub preprocess ($$) { #{{{ +sub preprocess ($$;$) { #{{{ my $page=shift; my $content=shift; + my $onlystrip=shift || 0; # strip directives without processing my $handle=sub { my $escape=shift; @@ -106,12 +112,17 @@ sub preprocess ($$) { #{{{ if (length $escape) { return "[[$command $params]]"; } + elsif ($onlystrip) { + return ""; + } elsif (exists $hooks{preprocess}{$command}) { - my %params; - while ($params =~ /(\w+)=\"([^"]+)"(\s+|$)/g) { - $params{$1}=$2; + # Note: preserve order of params, some plugins may + # consider it significant. + my @params; + while ($params =~ /(\w+)=\"?([^"]+)"?(\s+|$)/g) { + push @params, $1, $2; } - return $hooks{preprocess}{$command}{call}->(page => $page, %params); + return $hooks{preprocess}{$command}{call}->(@params, page => $page); } else { return "[[$command not processed]]"; @@ -162,8 +173,7 @@ sub genpage ($$$) { #{{{ my $title=pagetitle(basename($page)); - my $template=HTML::Template->new(blind_cache => 1, - filename => "$config{templatedir}/page.tmpl"); + my $template=template("page.tmpl", blind_cache => 1); my $actions=0; if (length $config{cgiurl}) { @@ -190,12 +200,6 @@ sub genpage ($$$) { #{{{ $template->param(have_actions => 1); } - if (exists $hooks{pagetemplate}) { - foreach my $id (keys %{$hooks{pagetemplate}}) { - $hooks{pagetemplate}{$id}{call}->($page, $template); - } - } - $template->param( title => $title, wikiname => $config{wikiname}, @@ -205,6 +209,12 @@ sub genpage ($$$) { #{{{ mtime => displaytime($mtime), styleurl => styleurl($page), ); + + if (exists $hooks{pagetemplate}) { + foreach my $id (keys %{$hooks{pagetemplate}}) { + $hooks{pagetemplate}{$id}{call}->($page, $template); + } + } return $template->output; } #}}} @@ -226,13 +236,11 @@ sub check_overwrite ($$) { #{{{ sub displaytime ($) { #{{{ my $time=shift; - if ($config{timeformat} eq '%c') { - return scalar(localtime($time)); # optimisation - } - else { - eval q{use POSIX}; - return POSIX::strftime($config{timeformat}, localtime($time)); - } + eval q{use POSIX}; + # strftime doesn't know about encodings, so make sure + # its output is properly treated as utf8 + return Encode::decode_utf8(POSIX::strftime( + $config{timeformat}, localtime($time))); } #}}} sub mtime ($) { #{{{