diff -ru \TocPlugin\lib\TWiki\Plugins\TocPlugin\Anchor.pm .\TocPlugin\Anchor.pm --- \TocPlugin\lib\TWiki\Plugins\TocPlugin\Anchor.pm Sun Oct 07 13:54:54 2001 +++ .\TocPlugin\Anchor.pm Wed Jan 15 09:53:26 2003 @@ -125,6 +125,10 @@ $this->unWikiWord($text) . ""; } + # Generate expanded HTML for printing + sub toPrint { + } + # Generate a string representation for debugging sub toString { my ($this, $nohtml) = @_; diff -ru \TocPlugin\lib\TWiki\Plugins\TocPlugin\Attrs.pm .\TocPlugin\Attrs.pm --- \TocPlugin\lib\TWiki\Plugins\TocPlugin\Attrs.pm Tue Sep 04 19:41:18 2001 +++ .\TocPlugin\Attrs.pm Wed Jan 15 09:53:26 2003 @@ -18,7 +18,7 @@ use integer; # Class of attribute sets -{ package Attrs; +{ package TocPlugin::Attrs; # Parse a standard attribute string containing name=value pairs. The # value may be a word or a quoted string (no escapes!) diff -ru \TocPlugin\lib\TWiki\Plugins\TocPlugin\Section.pm .\TocPlugin\Section.pm --- \TocPlugin\lib\TWiki\Plugins\TocPlugin\Section.pm Sun Oct 07 13:54:54 2001 +++ .\TocPlugin\Section.pm Wed Jan 15 09:53:26 2003 @@ -502,7 +502,7 @@ while ($text =~ s/%(SECTION[0-9]+|ANCHOR)({[^%]*})?%(.*)//o) { my $key = $1; - my $attrs = Attrs->new($2); + my $attrs = TocPlugin::Attrs->new($2); my $title = $3; $title =~ s/(^\s+|\s+$)//go; $attrs->set("text", $title); @@ -566,6 +566,28 @@ $res .= "" if ($listed && ! $nohtml); $res .= "}"; + return $res; + } + + # for webPrint function + sub toPrint { + my ($this, $wif, $toc, $web, $nohtml) = @_; + my $res = ""; + + if (defined($this->wikiName())) { + my $ct = $toc->_findTopic($this->wikiName); + my $text = $wif->readTopic($this->wikiName); + + # $res .= "Expanding wikiName= " . $wif->webName . "." . $this->wikiName() . " "; + $res .= TOC::_printWithTOCTags($toc, $wif, $ct, $text); + + } + + my $child; + foreach $child ( @{$this->{SECTIONS}} ) { + $res .= $child->toPrint($wif, $toc, $web, $nohtml); + } + return $res; } Only in \TocPlugin\lib\TWiki\Plugins\TocPlugin: test.zip diff -ru \TocPlugin\lib\TWiki\Plugins\TocPlugin\TOC.pm .\TocPlugin\TOC.pm --- \TocPlugin\lib\TWiki\Plugins\TocPlugin\TOC.pm Fri Sep 21 19:50:18 2001 +++ .\TocPlugin\TOC.pm Wed Jan 15 09:53:26 2003 @@ -1,4 +1,4 @@ -# + # Copyright (C) Motorola 2001 - All rights reserved # # TWiki extension that adds tags for the generation of tables of contents. @@ -25,7 +25,7 @@ # Private sub _processTag { - my ($toc, $wif, $tag, @params) = @_; + my ($toc, $wif, $ct, $tag, @params) = @_; if ($tag eq "TOCCHECK") { return $toc->processTOCCHECKTag(@params); @@ -36,13 +36,13 @@ } elsif ($tag eq "TOCDUMP") { return $toc->toString(0); } else { - my $ct = $toc->currentTopic(); +# my $ct = $toc->currentTopic(); return Section::_error("Bad $tag: Current topic not in WebOrder") unless $ct; if ($tag eq "ANCHOR") { my $anc = $ct->processANCHORTag(@params); return $anc->generateTarget() if $anc; } elsif ($tag eq "SECTION") { - my $ct = $toc->currentTopic(); +# my $ct = $toc->currentTopic(); my $sec = $ct->processSECTIONTag(@params); return $sec->generateTarget() if $sec; } elsif ($tag eq "REF") { @@ -68,28 +68,68 @@ while ($text =~ s/%((SECTION[0-9]+)|ANCHOR)({[^%]*})?%(.*)/\/o) { my $tag = $1; - my $attrs = Attrs->new($3); + my $attrs = TocPlugin::Attrs->new($3); + $attrs->set("text", $4); + if ($ct) { + if ($tag =~ s/SECTION([0-9]+)//o) { + my $level = $1; + $attrs->set("level", $ct->level() + $level); + $text =~ s/\/&_processTag($toc, $wif, $toc->currentTopic, "SECTION", $attrs)/eo; + } else { + $text =~ s/\/&_processTag($toc, $wif, $toc->currentTopic, "ANCHOR", $attrs)/eo; + } + } + } + # The order in which the other tags is done is irrelevant + my $nullatt = TocPlugin::Attrs->new(""); + $text =~ s/%(REF|REFTABLE){([^%]*)}%/&_processTag($toc, $wif, $toc->currentTopic, $1, TocPlugin::Attrs->new($2))/geo; + $text =~ s/%(TOCDUMP)%/&_processTag($toc, $wif, $toc->currentTopic, $1, $nullatt)/geo; + $text =~ s/%(TOCCHECK)%/&_processTag($toc, $wif, $toc->currentTopic, $1, $nullatt)/geo; + $text =~ s/%(CONTENTS)({[^%]*})?%/&_processTag($toc, $wif, $toc->currentTopic, $1, TocPlugin::Attrs->new($2))/geo; + return $text; + } + + sub _printWithTOCTags { + my ($toc, $wif, $ct, $text) = @_; + + # remove sections and anchors that were generated from the text + # from the current topic for reload as the content may have changed + $ct->purge() if $ct; + + # Anchors and sections must be done before we generate the table + # of contents and ref tables. + while ($text =~ + s/%((SECTION[0-9]+)|ANCHOR)({[^%]*})?%(.*)/\/o) { + my $tag = $1; + my $attrs = TocPlugin::Attrs->new($3); $attrs->set("text", $4); if ($tag =~ s/SECTION([0-9]+)//o) { my $level = $1; $attrs->set("level", $ct->level() + $level); - $text =~ s/\/&_processTag($toc, $wif, "SECTION", $attrs)/eo; + $text =~ s/\/&_processTag($toc, $wif, $ct, "SECTION", $attrs)/eo; } else { - $text =~ s/\/&_processTag($toc, $wif, "ANCHOR", $attrs)/eo; + $text =~ s/\/&_processTag($toc, $wif, $ct, "ANCHOR", $attrs)/eo; } } # The order in which the other tags is done is irrelevant - my $nullatt = Attrs->new(""); - $text =~ s/%(REF|REFTABLE){([^%]*)}%/&_processTag($toc, $wif, $1, Attrs->new($2))/geo; - $text =~ s/%(CONTENTS)({[^%]*})?%/&_processTag($toc, $wif, $1, Attrs->new($2))/geo; - $text =~ s/%(TOCCHECK)%/&_processTag($toc, $wif, $1, $nullatt)/geo; - $text =~ s/%(TOCDUMP)%/&_processTag($toc, $wif, $1, $nullatt)/geo; + my $nullatt = TocPlugin::Attrs->new(""); + $text =~ s/%(REF|REFTABLE){([^%]*)}%/&_processTag($toc, $wif, $ct, $1, TocPlugin::Attrs->new($2))/geo; + $text =~ s/%(CONTENTS)({[^%]*})?%/&_processTag($toc, $wif, $ct, $1, TocPlugin::Attrs->new($2))/geo; + $text =~ s/%(TOCCHECK)%/&_processTag($toc, $wif, $ct, $1, $nullatt)/geo; + $text =~ s/%(TOCDUMP)%/&_processTag($toc, $wif, $ct, $1, $nullatt)/geo; return $text; } + + my $toc = undef; + sub _webPrint { + my ($toc, $wif, $web) = @_; + return $toc->toPrint($toc, $wif, $web, 0); + } + sub processTopic { my ($wif, $web, $topic, $text) = @_; @@ -99,11 +139,18 @@ if (!$toc || $web ne $toc->web() || $topic eq "WebOrder") { my $mess; ($toc, $mess) = TopLevelSection::createTOC($web, $wif); + if ($toc && $topic eq "WebPrint") { + return _webPrint($toc, $wif, $web); + } + return Section::replaceAllTags($text, $mess) unless $toc; } my $ct = $toc->currentTopic(); - return Section::replaceAllTags($text, Section::_error("Topic $topic not in WebOrder")) unless $ct; +# CarlMikkelsen didn't understand why this test was here, and it got in his way, +# so he removed it. This is important so that there can be a topic NOT in WebOrder +# that uses tags other than %SECTION% and %ANCHOR%. +# return Section::replaceAllTags($text, Section::_error("Topic $topic not in WebOrder")) unless $ct; return _processTOCTags($toc, $wif, $text); } diff -ru \TocPlugin\lib\TWiki\Plugins\TocPlugin\TOCIF.pm .\TocPlugin\TOCIF.pm --- \TocPlugin\lib\TWiki\Plugins\TocPlugin\TOCIF.pm Sun Sep 23 13:44:36 2001 +++ .\TocPlugin\TOCIF.pm Wed Jan 15 09:53:26 2003 @@ -60,7 +60,15 @@ sub readTopic { my ($this, $topic) = @_; - return TWiki::Func::readTopic($this->webName(), $topic); + my $text = ""; + # read the topic + $text = TWiki::Func::readTopic($this->webName(), $topic); + # expand the variables -- in the context of the appropriate topic + $text = TWiki::Func::expandCommonVariables($text, $topic, $this->webName()); + # this can't be right -- turn verbatim tags into pre tags + $text =~ s//
/go;
+    $text =~ s/<\/verbatim>/<\/pre>/go;
+    return $text;
   }
 
   sub webDirList {
diff -ru \TocPlugin\lib\TWiki\Plugins\TocPlugin\TopLevelSection.pm .\TocPlugin\TopLevelSection.pm
--- \TocPlugin\lib\TWiki\Plugins\TocPlugin\TopLevelSection.pm	Sun Oct 07 13:54:54 2001
+++ .\TocPlugin\TopLevelSection.pm	Wed Jan 15 09:53:26 2003
@@ -106,7 +106,7 @@
     @tocNames = grep( /^\s+\*\s/, @tocNames );
       
     my $tocEntry;
-    my $attrs = Attrs->new("");
+    my $attrs = TocPlugin::Attrs->new("");
 
     # Check that each topic in the WebOrder only appears once
     my %seen;
@@ -206,6 +206,11 @@
       }
       getTopicList($section, $topics);
     }
+  }
+
+  sub toPrint {
+    my ($this, $toc, $wif, $web, $nohtml) = @_;
+    return $this->SUPER::toPrint($wif, $toc, $web, $nohtml);
   }
 
   sub toString {
diff -ru \TocPlugin\lib\TWiki\Plugins\TocPlugin.pm .\TocPlugin.pm
--- \TocPlugin\lib\TWiki\Plugins\TocPlugin.pm	Sun Sep 23 13:44:34 2001
+++ .\TocPlugin.pm	Wed Jan 15 09:53:09 2003
@@ -84,7 +84,7 @@
 }
 
 # =========================
-sub DISABLE_startRenderingHandler
+sub startRenderingHandler
 {
 ### my ( $text, $web ) = @_;   # do not uncomment, use $_[0], $_[1] instead
 
@@ -94,6 +94,7 @@
 
   # do custom extension rule, like for example:
   # $_[0] =~ s/old/new/go;
+  $_[0] = TOC::processTopic($wif, $web, $topic, $_[0]);
 }
 
 # =========================
@@ -123,7 +124,7 @@
 }
 
 # =========================
-sub endRenderingHandler
+sub DISABLE_endRenderingHandler
 {
 ### my ( $text ) = @_;   # do not uncomment, use $_[0] instead