<toc> == # Test == === # Test (again) === == # SandBox SampleUndefinedPage == === # I am ''italics'' and '''bold''' === ==== # I am <b>bold</b> and <i>italics</i> ==== === # I am a [http://example.com bracketed link]. === ==== # https://www.usemod.org/meatball.gif ====
You would get something like
for the MeatBall:TableOfContents, except each entry in the Table would be a link to its respective heading. -- SunirShah
Make $TableOfContents
a global as well as @HeadingNumbers
if you haven't already, and change WikiHeading to be:
sub WikiHeadingNumber { my ($depth,$text) = @_; my ($anchor, $number); return '' unless --$depth > 0; # Don't number H1s because it looks stupid while (scalar @HeadingNumbers < ($depth-1)) { push @HeadingNumbers, 1; $TableOfContents .= '<dl><dt> </dt><dd>'; } if (scalar @HeadingNumbers < $depth) { push @HeadingNumbers, 0; $TableOfContents .= '<dl><dt> </dt><dd>'; } while (scalar @HeadingNumbers > $depth) { pop @HeadingNumbers; $TableOfContents .= "</dd></dl>\n\n"; } $HeadingNumbers[$#HeadingNumbers]++; $number = (join '.', @HeadingNumbers) . '. '; # Remove embedded links. THIS IS FRAGILE! $text = &RestoreSavedText($text); $text =~ s/\<a\s[^\>]*?\>\?\<\/a\>//si; # No such page syntax $text =~ s/\<a\s[^\>]*?\>(.*?)\<\/a\>/$1/si; # Cook anchor by canonicalizing $text. $anchor = $text; $anchor =~ s/\<.*?\>//g; $anchor =~ s/\W/_/g; $anchor =~ s/__+/_/g; $anchor =~ s/^_//; $anchor =~ s/_$//; $anchor = '_' . (join '_', @HeadingNumbers) unless $anchor; # Last ditch effort $TableOfContents .= $number . &ScriptLink("$OpenPageName#$anchor",$text) . "</dd>\n<dt> </dt><dd>"; return &StoreHref(" name=\"$anchor\"") . $number; }
sub WikiHeading { my ($pre, $depth, $text) = @_;
$depth = length($depth); $depth = 6 if ($depth > 6); $text =~ s/^#\s+/&WikiHeadingNumber($depth,$')/e; # $' == $POSTMATCH return $pre . "<H$depth>$text</H$depth>\n"; }
sub RestoreSavedText { my ($text) = @_; $text =~ s/$FS(\d+)$FS/$SaveUrl{$1}/ge; # Restore saved text $text =~ s/$FS(\d+)$FS/$SaveUrl{$1}/ge; # Restore nested saved text return $text; }
sub WikiToHTML { ... $pageText = &WikiLinesToHtml($pageText); # Line-oriented markup while (@HeadingNumbers) { pop @HeadingNumbers; $TableOfContents .= "</dd></dl>\n\n"; } $pageText =~ s/<toc>/$TableOfContents/gi; return &RestoreSavedText($pageText); }
sub GetDiffHTML { ... @HeadingNumbers = (); $TableOfContents = ''; return $html; }
Note that WikiToHTML now returns after a call to &RestoreSavedText, which just moved the two lines that were previously there to their own function.