@@ -85,18 +85,19 @@ sub cleanup {
8585# Generate a new header that includes the number and the target anchor
8686sub addanchor {
8787 my ($chapno , $seqno , $stag , $lvl , $title , $content , $cmt , $etag ) = @_ ;
88- my ($anchor , $anchor1 , $txt , $i );
88+ my ($anchor , $anchor1 , $anchor2016 , $ txt , $i );
8989 my $file = $chapter [$chapno ];
9090
9191 # Generate the anchor
9292 if ($content =~ / <a\s +[^>]*?name\s *=\s *(?:([^\s\" >]+)|\" ([^\" ]+)\" |\' ([^\' ]+)\' )/io ) { # Reuse first anchor in header.
9393 $anchor = " $1$2$3 " ; # Only one of $1, $2, $3 will match.
9494 $anchor1 = " #$anchor " ;
9595 } else {
96- $anchor = " q$chapno .$seqno " ; # Use simple sequence number
96+ $anchor = " q$seqno " ; # Use simple sequence number
97+ $anchor2016 = " q$chapno .$seqno " ; # 2016 anchors
9798 $anchor1 = " #$anchor " ;
9899 }
99- # $anchor1 = "" if ($lvl == 1); # if H1, just go to the top of the page
100+ $anchor1 = " " if ($lvl == 1); # if H1, just go to the top of the page
100101
101102 # Increment the count, reset higher level counts
102103 $counts [$lvl ]++;
@@ -121,12 +122,22 @@ sub addanchor {
121122 if ($content =~ / <a\s +[^>]*?name\s *=/sio ) {
122123 # Don't add anchors if there is already an anchor
123124 return " $stag$num $content$etag " ;
124- } elsif ($content =~ / <a\b /sio ) {
125- # There is an A tag, insert anchor before it
126- return " $stag <a name=\" $anchor \" >$num $` </a>$& $' $etag " ;
127125 } else {
128- # There is no A tag, enclose whole content
129- return " $stag <a name=\" $anchor \" >$num $content </a>$etag " ;
126+ my ($anchor_start , $anchor_end );
127+ if (defined $anchor2016 ) {
128+ $anchor_start = " <span id=\" $anchor2016 \" ><a name=\" $anchor \" >" ;
129+ $anchor_end = " </a></span>" ;
130+ } else {
131+ $anchor_start = " <a name=\" $anchor \" >" ;
132+ $anchor_end = " </a>" ;
133+ }
134+ if ($content =~ / <a\b /sio ) {
135+ # There is an A tag, insert anchor before it
136+ return " $stag$anchor_start$num $` $anchor_end $& $' $etag " ;
137+ } else {
138+ # There is no A tag, enclose whole content
139+ return " $stag$anchor_start$num $content$anchor_end$etag " ;
140+ }
130141 }
131142}
132143
0 commit comments