33# The files are rwritten.
44# Arnaud Le Hors - lehors@w3.org
55# Modifications by Bert Bos <bert@w3.org>
6- # $Id: addhanch,v 2.2 1998-04-06 23:51:21 ijacobs Exp $
6+ # $Id: addhanch,v 2.3 2002-08-02 18:12:19 bbos Exp $
77
88use DB_File;
99use Getopt::Std;
@@ -89,16 +89,14 @@ sub addanchor {
8989 my $file = $chapter [$chapno ];
9090
9191 # Generate the anchor
92- if ($lvl == 1) { # if H1, just go to the top of the page
93- $anchor = " " ;
94- $anchor1 = " " ;
95- } elsif ($content =~ / <a\s +[^>]*?name\s *=\s *(?:([^\s\" >]+)|\" ([^\" ]+)\" |\' ([^\' ]+)\' )/io ) { # Reuse first anchor in header.
92+ if ($content =~ / <a\s +[^>]*?name\s *=\s *(?:([^\s\" >]+)|\" ([^\" ]+)\" |\' ([^\' ]+)\' )/io ) { # Reuse first anchor in header.
9693 $anchor = " $1$2$3 " ; # Only one of $1, $2, $3 will match.
9794 $anchor1 = " #$anchor " ;
9895 } else {
9996 $anchor = " q$seqno " ; # Use simple sequence number
10097 $anchor1 = " #$anchor " ;
10198 }
99+ $anchor1 = " " if ($lvl == 1); # if H1, just go to the top of the page
102100
103101 # Increment the count, reset higher level counts
104102 $counts [$lvl ]++;
@@ -120,8 +118,8 @@ sub addanchor {
120118 $anchors {$dbkey } = $dbentry ;
121119
122120 # Construct the new heading
123- if ($lvl == 1 || $ content =~ / <a\s +[^>]*?name\s *=/sio ) {
124- # Don't add anchors if H1, or if there is already an anchor
121+ if ($content =~ / <a\s +[^>]*?name\s *=/sio ) {
122+ # Don't add anchors if there is already an anchor
125123 return " $stag$num $content$etag " ;
126124 } elsif ($content =~ / <a\b /sio ) {
127125 # There is an A tag, insert anchor before it
0 commit comments