]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Render.pm
* POSIX::strftime doesn't know about encodings and doesn't return a utf8
[ikiwiki.git] / IkiWiki / Render.pm
index c5922c933a7516b9a06476ce68855e9289664c97..d23dfdc2538716780cb80f94c05876562f9ea0e0 100644 (file)
@@ -29,13 +29,16 @@ 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)));
+               # XXX explanation of this insanity wating on perl bug number
+               $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 +98,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 +110,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,12 +199,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 +208,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 +235,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 ($) { #{{{
@@ -426,7 +433,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