== # heading2 = === # heading3 == ==== # heading4 ===
would emit
Note that H1s aren't numbered because that looks really lame.
For the originating context, see MeatBall:NamedAnchorsInWiki. You may also want to apply the /TableOfContents patch after this.
-- SunirShah
Add @HeadingNumbers
to the global variable list, we patch WikiHeading? ala:</nowiki>
sub WikiHeadingNumber { my ($depth) = @_; return '' unless --$depth > 0; # H1s aren't numbered because it looks stupid. push @HeadingNumbers, 1 while scalar @HeadingNumbers < ($depth-1); push @HeadingNumbers, 0 if scalar @HeadingNumbers < $depth; pop @HeadingNumbers while scalar @HeadingNumbers > $depth; $HeadingNumbers[$#HeadingNumbers]++; my $anchor = join '_', @HeadingNumbers; return &StoreHref(" name=\"$anchor\"") . (join '.', @HeadingNumbers) . '. '; }
sub WikiHeading { my ($pre, $depth, $text) = @_;
$depth = length($depth); $depth = 6 if ($depth > 6); $text =~ s/^\s*#\s+/&WikiHeadingNumber($depth)/e; return $pre . "<H$depth>$text</H$depth>\n"; }
== # ...1 == == # ...2 == === # ...2.1 === === # ...2.2 === == # ...3 == ==== # ...3.1.1 ==== === # 3.2 === ======= # 3.2.1.1.1.1 ======= ==== # 3.2.2 ==== === # 3.3 ===