--- ConditionalPlugin.pm.orig 2002-08-11 12:24:03.000000000 -0400 +++ ConditionalPlugin.pm 2003-01-24 21:42:38.000000000 -0500 @@ -38,10 +38,13 @@ # ========================= package TWiki::Plugins::ConditionalPlugin; # ========================= +use strict; use vars qw( - $VERSION $debug $sandbox $pluginInitialized + $VERSION $debug $sandbox $pluginInitialized $prefixPattern $ops + $condPattern_ifonly $condPattern_ifelse $postfixPattern $topic $web + $user $installWeb ); #use Safe; @@ -111,16 +114,32 @@ return; } _initDefaults() if( ! $pluginInitialized ); - - # try to match if/else first (otherwise it gets masked by the if-only - # variant - $_[0] =~ s/$prefixPattern$condPattern_ifelse$postfixPattern/&handleConditional($3, $5, $6)/geo; - - # try to match the if-only variant - $_[0] =~ s/$prefixPattern$condPattern_ifonly$postfixPattern/&handleConditional($3, $5, '')/geos; - + + # Nested if support - find the last occurence of %IF each time through and + # process it first. Thus, the deepest nesting in each set of ifs is + # processed first and parsed correctly. -- Walter Mundt + + my $text = \$_[0]; + my $ifIndex = rindex($$text, "%IF"); + while ($ifIndex != -1) { + my $startText = substr($$text, 0, $ifIndex); + my $endText = substr($$text, $ifIndex); + + # try to match if/else first (otherwise it gets masked by the if-only + # variant + $endText =~ s/$prefixPattern$condPattern_ifelse$postfixPattern/&handleConditional($3, $5, $6)/geos; + + # then try to match the if-only variant + $endText =~ s/$prefixPattern$condPattern_ifonly$postfixPattern/&handleConditional($3, $5, '')/geos; + + # mark any remaining %IFs as invalid syntax + $endText =~ s/^%IF/!!IF/s; + + $$text = $startText . $endText; + $ifIndex = rindex($$text, "%IF"); + } } # ========================= sub DISABLE_startRenderingHandler