--- origineel 2004-11-01 16:56:39.000000000 +0100 +++ TWiki.pm 2004-11-01 18:23:05.000000000 +0100 @@ -1,4 +1,5 @@ # Main Module of TWiki Collaboration Platform, http://TWiki.org/ +# $Id: TWiki.pm,v 1.3 2004/11/01 17:23:00 rdgon Exp $ # ($wikiversion has version info) # # Copyright (C) 1999-2003 Peter Thoeny, peter@thoeny.com @@ -1604,6 +1605,7 @@ my $tabs = ""; my $anchor = ""; my $highest = 99; + my %toc_anchors; foreach $line ( @list ) { if( $line =~ /^.*
.*$/io ) {
             $insidePre = 1;
@@ -1630,7 +1632,8 @@
                 $line  =~ s/$headerPatternHt/$2/gio;
             }
             if( ( $line ) && ( $level <= $depth ) ) {
-                $anchor = makeAnchorName( $line );
+                $anchor = makeAnchorName( $line, \%toc_anchors );
+		
                 # cut TOC exclude '---+ heading !! exclude'
                 $line  =~ s/\s*$headerPatternNoTOC.+$//go;
                 next unless $line;
@@ -2275,9 +2278,12 @@
 
 # =========================
 # Build an HTML  element with suitable anchor for linking from %TOC%
+# parameters
+#	third: theHash: hash with names of already created anchors for
+#					making unique anchor names
 sub makeAnchorHeading
 {
-    my( $theText, $theLevel ) = @_;
+    my( $theText, $theLevel, $theHash ) = @_;
 
     # - Need to build '

text

' # type markup. @@ -2287,7 +2293,7 @@ # - filter out $headerPatternNoTOC ( '!!' and '%NOTOC%' ) my $text = $theText; - my $anchorName = &makeAnchorName( $text ); + my $anchorName = &makeAnchorName( $text, $theHash ); $text =~ s/$headerPatternNoTOC//o; # filter '!!', '%NOTOC%' my $hasAnchor = 0; # text contains potential anchor $hasAnchor = 1 if( $text =~ m/{$proposed_anchor})) + { # anchor already exists; try one with the next serial number + $proposed_anchor = "${anchorName}_$sn"; + $sn++; + } + $anchorName = $proposed_anchor; + $known_anchors->{$anchorName} = 1; + } + return $anchorName; } @@ -2536,6 +2557,7 @@ # Wiki Plugin Hook &TWiki::Plugins::startRenderingHandler( $text, $theWeb, $meta ); + my %html_anchors; foreach( split( /\n/, $text ) ) { # change state: @@ -2599,11 +2621,11 @@ # Headings # '
...
' HTML rule - s/$headerPatternHt/&makeAnchorHeading($2,$1)/geoi; + s/$headerPatternHt/&makeAnchorHeading($2,$1,\%html_anchors )/geoi; # '\t+++++++' rule - s/$headerPatternSp/&makeAnchorHeading($2,(length($1)))/geo; + s/$headerPatternSp/&makeAnchorHeading($2,(length($1)),\%html_anchors )/geo; # '----+++++++' rule - s/$headerPatternDa/&makeAnchorHeading($2,(length($1)))/geo; + s/$headerPatternDa/&makeAnchorHeading($2,(length($1)),\%html_anchors )/geo; # Horizontal rule s/^---+/
/;