]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Render.pm
* Use DESTDIR and not PREFIX to specify installation prefix for packaging.
[ikiwiki.git] / IkiWiki / Render.pm
index d988e09563f3eac4598f5fbeee81fff78708a88f..f386697287a0d341e74881867162cbd20acc017b 100644 (file)
@@ -84,11 +84,10 @@ sub parentlinks ($) { #{{{
        return @ret;
 } #}}}
 
-sub preprocess ($$$;$) { #{{{
+sub preprocess ($$$) { #{{{
        my $page=shift; # the page the data comes from
        my $destpage=shift; # the page the data will appear in (different for inline)
        my $content=shift;
-       my $onlystrip=shift || 0; # strip directives without processing
 
        my $handle=sub {
                my $escape=shift;
@@ -97,19 +96,31 @@ sub preprocess ($$$;$) { #{{{
                if (length $escape) {
                        return "[[$command $params]]";
                }
-               elsif ($onlystrip) {
-                       return "";
-               }
                elsif (exists $hooks{preprocess}{$command}) {
                        # Note: preserve order of params, some plugins may
                        # consider it significant.
                        my @params;
-                       while ($params =~ /(?:(\w+)=)?(?:"""(.+)"""|"([^"]+)"|(\S+))(?:\s+|$)/sg) {
-                               if (defined $1) {
-                                       push @params, $1, (defined $2 ? $2 : (defined $3 ? $3 : $4));
+                       while ($params =~ /(?:(\w+)=)?(?:"""(.*?)"""|"([^"]+)"|(\S+))(?:\s+|$)/sg) {
+                               my $key=$1;
+                               my $val;
+                               if (defined $2) {
+                                       $val=$2;
+                                       $val=~s/\r\n/\n/mg;
+                                       $val=~s/^\n+//g;
+                                       $val=~s/\n+$//g;
+                               }
+                               elsif (defined $3) {
+                                       $val=$3;
+                               }
+                               elsif (defined $4) {
+                                       $val=$4;
+                               }
+
+                               if (defined $key) {
+                                       push @params, $key, $val;
                                }
                                else {
-                                       push @params, (defined $2 ? $2 : (defined $3 ? $3 : $4)), '';
+                                       push @params, $val, '';
                                }
                        }
                        return $hooks{preprocess}{$command}{call}->(
@@ -123,7 +134,7 @@ sub preprocess ($$$;$) { #{{{
                }
        };
        
-       $content =~ s{(\\?)\[\[(\w+)\s+((?:(?:\w+=)?(?:""".+"""|"[^"]+"|[^\s\]]+)\s*)*)\]\]}{$handle->($1, $2, $3)}eg;
+       $content =~ s{(\\?)\[\[(\w+)\s+((?:(?:\w+=)?(?:""".*?"""|"[^"]+"|[^\s\]]+)\s*)*)\]\]}{$handle->($1, $2, $3)}seg;
        return $content;
 } #}}}
 
@@ -266,8 +277,8 @@ sub render ($) { #{{{
                
                $links{$page}=[findlinks($page, $content)];
                
-               $content=linkify($page, $page, $content);
                $content=preprocess($page, $page, $content);
+               $content=linkify($page, $page, $content);
                $content=htmlize($type, $content);
                
                check_overwrite("$config{destdir}/".htmlpage($page), $page);