@@ -33,7 +33,24 @@ async function checkLinks() {
3333 return getLineNumber ;
3434 } ;
3535
36- const checkPathForHash = ( hrefOrSrc , ids = [ ] , hash ) => {
36+ const getHashCheckHandler = ( hrefOrSrc ) => {
37+ return options . hashCheckHandlers . find ( ( { pattern } ) =>
38+ pattern . test ( hrefOrSrc )
39+ ) ;
40+ } ;
41+
42+ const getReactPartial = ( hrefOrSrc , html ) => {
43+ const handler = getHashCheckHandler ( hrefOrSrc ) ;
44+ if ( handler ) return handler . getPartial ( html ) ;
45+ return undefined ;
46+ } ;
47+
48+ const checkPathForHash = (
49+ hrefOrSrc ,
50+ ids = [ ] ,
51+ hash ,
52+ { reactPartial } = { }
53+ ) => {
3754 // On some websites, the ids may not exactly match the hash included
3855 // in the link.
3956 // For e.g. GitHub will prepend client facing ids with their own
@@ -43,10 +60,8 @@ async function checkLinks() {
4360 // as being 'user-content-foo-bar' for its own page processing purposes.
4461 //
4562 // See https://github.com/w3c/aria-practices/issues/2809
46- const handler = options . hashCheckHandlers . find ( ( { pattern } ) =>
47- pattern . test ( hrefOrSrc )
48- ) ;
49- if ( handler ) return handler . matchHash ( ids , hash ) ;
63+ const handler = getHashCheckHandler ( hrefOrSrc ) ;
64+ if ( handler ) return handler . matchHash ( ids , hash , { reactPartial } ) ;
5065 else return ids . includes ( hash ) ;
5166 } ;
5267
@@ -149,7 +164,15 @@ async function checkLinks() {
149164 . querySelectorAll ( '[id]' )
150165 . map ( ( idElement ) => idElement . getAttribute ( 'id' ) ) ;
151166
152- return { ok : response . ok , status : response . status , ids } ;
167+ // Handle GitHub README links.
168+ // These links are stored within a react-partial element
169+ const reactPartial = getReactPartial ( hrefOrSrc , html ) ;
170+ return {
171+ ok : response . ok ,
172+ status : response . status ,
173+ ids,
174+ reactPartial,
175+ } ;
153176 } catch ( error ) {
154177 return {
155178 errorMessage :
@@ -305,7 +328,9 @@ async function checkLinks() {
305328 if (
306329 ! isHashCheckingDisabled &&
307330 hash &&
308- ! checkPathForHash ( hrefOrSrc , pageData . ids , hash )
331+ ! checkPathForHash ( hrefOrSrc , pageData . ids , hash , {
332+ reactPartial : pageData . reactPartial ,
333+ } )
309334 ) {
310335 consoleError (
311336 `Found broken external link on ${ htmlPath } :${ lineNumber } :${ columnNumber } , ` +
0 commit comments