--- lib/TWiki.pm 2005/08/03 13:23:38 1.1 +++ lib/TWiki.pm 2005/08/03 14:15:24 @@ -2005,6 +2005,39 @@ =cut +# ========================= +#MPS +# Hooks for later expansion +# Allows plugins to be added for these. + +sub handleSectionStart +{ + my( $theAttributes, $theTopic, $theWeb, $verbatim, @theProcessedTopics ) = @_; + my $text = ""; + return $text; +} + +sub handleSectionEnd +{ + my( $theAttributes, $theTopic, $theWeb, $verbatim, @theProcessedTopics ) = @_; + my $text = ""; + return $text; +} + +sub getSection { + my $section = shift || return ""; + my $text = shift ||""; + if ($text =~ /%SECTION{[^%]*$section[^%]*}%/) { + # Remove text preceding the section marker + $text =~ s/.*?%SECTION{[^%]*$section[^%]*}%//s; + # Remove text following the first following end of section marker + $text =~ s/%ENDSECTION({[^%]*$section[^%]*})?%.*//s; + } else { + $text = ""; # Section doesn't exist - include no text + } + return $text; +} + sub handleIncludeFile { my( $theAttributes, $theTopic, $theWeb, $verbatim, @theProcessedTopics ) = @_; @@ -2012,6 +2045,7 @@ my $pattern = extractNameValuePair( $theAttributes, "pattern" ); my $rev = extractNameValuePair( $theAttributes, "rev" ); my $warn = extractNameValuePair( $theAttributes, "warn" ); + my $section = extractNameValuePair( $theAttributes, "section" ); if( $incfile =~ /^http\:/ ) { # include web page @@ -2090,9 +2124,14 @@ } else { ( $meta, $text ) = &TWiki::Store::readTopic( $theWeb, $theTopic ); } - # remove everything before %STARTINCLUDE% and after %STOPINCLUDE% - $text =~ s/.*?%STARTINCLUDE%//s; - $text =~ s/%STOPINCLUDE%.*//s; + if( $section ) { + # This is where we handle sections + $text = getSection($section, $text); + } else { + # remove everything before %STARTINCLUDE% and after %STOPINCLUDE% + $text =~ s/.*?%STARTINCLUDE%//s; + $text =~ s/%STOPINCLUDE%.*//s; + } } # else is a file with relative path, e.g. $dataDir/../../path/to/non-twiki/file.ext @@ -2991,8 +3030,6 @@ $_[0] =~ s/%STATISTICSTOPIC%/$statisticsTopicname/g; $_[0] =~ s/%STARTINCLUDE%//g; $_[0] =~ s/%STOPINCLUDE%//g; - $_[0] =~ s/%SECTION{(.*?)}%//g; - $_[0] =~ s/%ENDSECTION%//g; my $ok = 16; # SEARCH may be nested up to 16 times TRY: while( $_[0] =~ s/%SEARCH{(.*?)}%/&handleSearchWeb($1,$_[2],$_[1])/ge ) { last TRY unless( --$ok ); @@ -3149,6 +3186,8 @@ # recursively process multiple embedded %INCLUDE% statements and prefs $text =~ s/%INCLUDE{(.*?)}%/&handleIncludeFile($1, $theTopic, $theWeb, \@verbatim, @theProcessedTopics )/ge; + $text =~ s/%SECTION{(.*?)}%/&handleSectionStart($1, $theTopic, $theWeb, \@verbatim, @theProcessedTopics )/ge; + $text =~ s/%ENDSECTION({(.*?)})?%/&handleSectionEnd($1, $theTopic, $theWeb,\@verbatim, @theProcessedTopics )/ge; # TWiki Plugin Hook &TWiki::Plugins::commonTagsHandler( $text, $theTopic, $theWeb, 0 );