-- DavidBright
The patch is in unified diff format.
--- ../usemod10/wiki.pl 2003-09-11 07:21:02.000000000 -0500 +++ wiki.pl 2003-09-23 09:08:56.000000000 -0500 @@ -1681,7 +1715,7 @@ s/('*)'''(.*?)'''/$1<strong>$2<\/strong>/g; s/''(.*?)''/<em>$1<\/em>/g; if ($UseHeadings) { - s/(^|\n)\s*(\=+)\s+([^\n]+)\s+\=+/&WikiHeading($1, $2, $3)/geo; + s/(^|\n)\s*(\=+)\s*(#)?\s+([^\n]+)\s+\=+/&WikiHeading($1, $2, $4, $3)/geo; } if ($TableMode) { s/((\|\|)+)/"<\/TD><TD COLSPAN=\"" . (length($1)\/2) . "\">"/ge; @@ -2093,7 +2127,7 @@ } sub WikiHeadingNumber { - my ($depth, $text) = @_; + my ($depth, $text, $useNumber) = @_; my ($anchor, $number); return '' unless --$depth > 0; # Don't number H1s because it looks stupid @@ -2124,17 +2158,26 @@ $anchor =~ s/_$//; # Last ditch effort $anchor = '_' . (join '_', @HeadingNumbers) unless $anchor; - $TableOfContents .= $number . &ScriptLink("$OpenPageName#$anchor",$text) - . "</dd>\n<dt> </dt><dd>"; + if ($useNumber) { + $TableOfContents .= $number . &ScriptLink("$OpenPageName#$anchor",$text) + . "</dd>\n<dt> </dt><dd>"; + } else { + $TableOfContents .= &ScriptLink("$OpenPageName#$anchor",$text) + . "</dd>\n<dt> </dt><dd>"; + } return &StoreHref(" name=\"$anchor\"") . $number; } sub WikiHeading { - my ($pre, $depth, $text) = @_; + my ($pre, $depth, $text, $useNumber) = @_; $depth = length($depth); $depth = 6 if ($depth > 6); - $text =~ s/^\s*#\s+/&WikiHeadingNumber($depth,$')/e; # $' == $POSTMATCH + if ($useNumber) { + $text =~ &WikiHeadingNumber($depth,$text, 1); + } else { + $text =~ &WikiHeadingNumber($depth,$text, 0); + } return $pre . "<H$depth>$text</H$depth>\n"; }
Try an alternate token for un-numbered headings (##) like so:
In sub WikiHeading?:
$text =~ s/^\s*#\s+/&WikiHeadingNumber($depth,$')/e; # $' == $POSTMATCH + $text =~ s/^\s*##\s+/&WikiHeadingNumber($depth,$',1)/e; # $' == $POSTMATCH
In sub WikiHeadingNumber?:
- my ($depth, $text) = @_; + my ($depth, $text, $nonum) = @_; ... - $number = (join '.', @HeadingNumbers) . '. '; + $number = (join '.', @HeadingNumbers) . '. ' unless $nonum;This also supports both # and ## in the same document for a mix of the two.
-- JohnDoe?
Bloody briliant! Works like a charm. -- PEZ
--- wiki.pl.orig 2005-10-31 01:13:56.156250000 +0800 +++ wiki.pl 2005-10-31 01:22:31.843750000 +0800 @@ -1681,7 +1681,7 @@ s/('*)'''(.*?)'''/$1<strong>$2<\/strong>/g; s/''(.*?)''/<em>$1<\/em>/g; if ($UseHeadings) { - s/(^|\n)\s*(\=+)\s+([^\n]+)\s+\=+/&WikiHeading($1, $2, $3)/geo; + s/(^|\n)\s*(\=+)\s*(#)?\s+([^\n]+)\s+\=+/&WikiHeading($1, $2, $4, $3)/geo; } if ($TableMode) { s/((\|\|)+)/"<\/TD><TD COLSPAN=\"" . (length($1)\/2) . "\">"/ge; @@ -2093,7 +2093,7 @@ } sub WikiHeadingNumber { - my ($depth, $text) = @_; + my ($depth, $text, $useNumber) = @_; my ($anchor, $number); return '' unless --$depth > 0; # Don't number H1s because it looks stupid @@ -2126,15 +2126,23 @@ $anchor = '_' . (join '_', @HeadingNumbers) unless $anchor; $TableOfContents .= $number . &ScriptLink("$OpenPageName#$anchor",$text) . "</dd>\n<dt> </dt><dd>"; - return &StoreHref(" name=\"$anchor\"") . $number; + if ($useNumber) { + return &StoreHref(" name=\"$anchor\"") . $number; + } else { + return &StoreHref(" name=\"$anchor\""); + } } sub WikiHeading { - my ($pre, $depth, $text) = @_; + my ($pre, $depth, $text, $useNumber) = @_; $depth = length($depth); $depth = 6 if ($depth > 6); - $text =~ s/^\s*#\s+/&WikiHeadingNumber($depth,$')/e; # $' == $POSTMATCH + if ($useNumber) { + $text = &WikiHeadingNumber($depth,$text, 1) . $text; + } else { + $text = &WikiHeadingNumber($depth,$text, 0) . $text; + } return $pre . "<H$depth>$text</H$depth>\n"; }
-- Johnson