--- lib/TWiki.pm.org 2008-08-10 16:54:19.000000000 +0200 +++ lib/TWiki.pm 2008-08-11 18:28:59.000000000 +0200 @@ -1976,4 +1976,7 @@ } + # used to store all generated anchor names + my %references = (); + my $insidePre = 0; my $insideVerbatim = 0; @@ -2014,5 +2017,22 @@ $line =~ s/\s*$regex{headerPatternNoTOC}.+$//go; next unless $line; - my $anchor = $this->renderer->makeAnchorName( $line ); + + # SMELL: we're forced to *duplicate* the exact steps from + # $this->renderer->_makeAnchorHeading(...) here + my $anchor = $this->renderer->makeAnchorName( $line, 0 ); + my $compatAnchor = $this->renderer->makeAnchorName( $line, 1 ); + + # ensure that all generated anchor names are unique + my $cnt = 2; + my $suffix = ''; + while ((exists $references{$anchor . $suffix}) || + (exists $references{$compatAnchor . $suffix})) { + $suffix = '_' . $cnt++; + } + $anchor .= $suffix; + $compatAnchor .= $suffix; + $references{$anchor} = 1; + $references{$compatAnchor} = 1; + $highest = $level if( $level < $highest ); my $tabs = "\t" x $level; --- lib/TWiki/Render.pm.org 2008-08-10 16:54:19.000000000 +0200 +++ lib/TWiki/Render.pm 2008-08-11 18:31:15.000000000 +0200 @@ -21,4 +21,7 @@ $placeholderMarker = 0; +# Used to generate unique anchors +my %headings; + # defaults for trunctation of summary text my $TMLTRUNC = 162; @@ -357,4 +360,17 @@ my $anchorName = $this->makeAnchorName( $text, 0 ); my $compatAnchorName = $this->makeAnchorName( $text, 1 ); + + # ensure that all generated anchor names are unique + my $cnt = 2; + my $suffix = ''; + while ((exists $headings{$anchorName . $suffix}) || + (exists $headings{$compatAnchorName . $suffix})) { + $suffix = '_' . $cnt++; + } + $anchorName .= $suffix; + $compatAnchorName .= $suffix; + $headings{$anchorName} = 1; + $headings{$compatAnchorName} = 1; + # filter '!!', '%NOTOC%' $text =~ s/$TWiki::regex{headerPatternNoTOC}//o; @@ -884,4 +900,6 @@ @{$this->{LIST}} = (); + %headings = (); + # Initial cleanup $text =~ s/\r//g;