X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/65d0aee407f81db9ca2261fc8ecb1958f62302a9..b0e7e2e123079a2e68924cfb90d19c44571b1f65:/IkiWiki/Render.pm diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index df08eb49c..d4e498188 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -29,12 +29,10 @@ sub htmlize ($$) { #{{{ $blosxom::version="is a proper perl module too much to ask?"; use warnings 'all'; do "/usr/bin/markdown"; - require Encode; + use Encode; } 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))); } else { @@ -95,9 +93,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 +105,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]]"; @@ -190,21 +194,21 @@ 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}, parentlinks => [parentlinks($page)], content => $content, backlinks => [backlinks($page)], - mtime => scalar(gmtime($mtime)), + 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; } #}}} @@ -223,6 +227,18 @@ 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)); + } +} #}}} + sub mtime ($) { #{{{ my $file=shift; @@ -414,7 +430,7 @@ FILE: foreach my $file (@files) { } # Handle backlinks; if a page has added/removed links, update the - # pages it links to. Also handles rebuilding dependat pages. + # pages it links to. Also handles rebuilding dependant pages. # TODO: inefficient; pages may get rendered above and again here; # problem is the backlinks could be wrong in the first pass render # above