X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/7c66edacd864bdb1a7c657b6131f53666fc0675b..46c33b38324e9e71a9126f1aabd5e73e3358b22b:/IkiWiki/Render.pm diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 5351ee7ad..f38669728 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -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,18 +96,28 @@ 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+)=)?(?:"""\n?(.+)"""|"([^"]+)"|(\S+))(?:\s+|$)/sg) { - my $val=(defined $2 ? $2 : (defined $3 ? $3 : $4)); - chomp $val; - if (defined $1) { - push @params, $1, $val; + 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, $val, ''; @@ -125,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; } #}}} @@ -268,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);