]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Render.pm
* Add toc (table of contents) plugin.
[ikiwiki.git] / IkiWiki / Render.pm
index cef770c6784025d89c2b1d64ffeca2391d5c3749..58556148f21fa216f04aaa3a827794384e6db2d7 100644 (file)
@@ -84,11 +84,11 @@ sub parentlinks ($) { #{{{
        return @ret;
 } #}}}
 
-sub preprocess ($$$;$) { #{{{
+my %preprocessing;
+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,9 +97,6 @@ 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.
@@ -127,14 +124,21 @@ sub preprocess ($$$;$) { #{{{
                                        push @params, $val, '';
                                }
                        }
-                       return $hooks{preprocess}{$command}{call}->(
+                       if ($preprocessing{$page}++ > 10) {
+                               # Avoid loops of preprocessed pages preprocessing
+                               # other pages that preprocess them, etc.
+                               return "[[$command preprocessing loop detected on $page at depth $preprocessing{$page}]]";
+                       }
+                       my $ret=$hooks{preprocess}{$command}{call}->(
                                @params,
                                page => $page,
                                destpage => $destpage,
                        );
+                       $preprocessing{$page}--;
+                       return $ret;
                }
                else {
-                       return "[[$command not processed]]";
+                       return "[[$command $params]]";
                }
        };