@@ -915,11 +915,13 @@ __webpack_require__.r(__webpack_exports__);
915
915
/**
916
916
* Add anchor links to any H2 - H6 within the <main> element that:
917
917
* - are not children of a <nav> element
918
- * - do not have an ancestor with the data-anchor="no" attribute
919
- * - do not themselves have the data-anchor="no" attribute
918
+ * - do not have an ancestor with the data-anchor="no" attribute, with
919
+ * the `hidden` attribute or with the .visuallyhidden class
920
+ * - do not themselves have the data-anchor="no" attribute, the `hidden`
921
+ * attribute or the .visuallyhidden class
920
922
*
921
- * If a heading does not already possess an ID, use regular expressions
922
- * on the textContent of the heading to generate a string that is valid to
923
+ * If a heading does not already possess an ID, use regular expressions on
924
+ * the textContent of the heading to generate a string that is valid to
923
925
* use for both the heading ID and the anchor href. Supports non-Latin
924
926
* scripts by matching any Unicode letter - \p{L} - or number - \p{N}. The
925
927
* u flag enables Unicode matching, to support characters from any script.
@@ -938,12 +940,20 @@ let headingAnchors = function () {
938
940
// Filter out headings that:
939
941
// - Are not children of <nav>
940
942
// - Do not have an ancestor with the data-anchor="no" attribute
943
+ // - Do not have an ancestor with the `hidden` attribute
944
+ // - Do not have an ancestor with the `.visuallyhidden` class
941
945
// - Do not themselves have the data-anchor="no" attribute
946
+ // - Do not themselves have the `hidden` attribute
947
+ // - Do not themselves have the `.visuallyhidden` class
942
948
let targetedHeadings = headingsArray . filter ( function ( heading ) {
943
949
let insideNav = heading . closest ( 'nav' ) !== null ;
944
950
let parentHasDataAttribute = heading . closest ( '[data-anchor="no"]' ) !== null ;
951
+ let hiddenParent = heading . closest ( '[hidden]' ) !== null ;
952
+ let visuallyhiddenParent = heading . closest ( '.visuallyhidden' ) !== null ;
945
953
let hasDataAttribute = heading . getAttribute ( 'data-anchor' ) === 'no' ;
946
- return ! insideNav && ! parentHasDataAttribute && ! hasDataAttribute ;
954
+ let isHidden = heading . getAttribute ( 'hidden' ) ;
955
+ let isVisuallyhidden = heading . classList . contains ( 'visuallyhidden' ) ;
956
+ return ! insideNav && ! parentHasDataAttribute && ! hiddenParent && ! visuallyhiddenParent && ! hasDataAttribute && ! isHidden && ! isVisuallyhidden ;
947
957
} ) ;
948
958
if ( targetedHeadings . length > 0 ) {
949
959
targetedHeadings . forEach ( function ( heading ) {
@@ -964,7 +974,7 @@ let headingAnchors = function () {
964
974
}
965
975
anchor . setAttribute ( 'href' , '#' + anchorHref ) ;
966
976
anchor . setAttribute ( 'class' , 'heading-anchor' ) ;
967
- anchor . innerHTML = '<span aria-hidden="true"># </span>' + '<span class="visuallyhidden">' + _translations__WEBPACK_IMPORTED_MODULE_0__ . translate . translate ( 'anchor' , languageCode ) + '</span>' ;
977
+ anchor . innerHTML = '<span aria-hidden="true">§ </span>' + '<span class="visuallyhidden">' + _translations__WEBPACK_IMPORTED_MODULE_0__ . translate . translate ( 'anchor' , languageCode ) + '</span>' ;
968
978
heading . appendChild ( anchor ) ;
969
979
} ) ;
970
980
}
0 commit comments