@@ -33,7 +33,24 @@ async function checkLinks() {
33
33
return getLineNumber ;
34
34
} ;
35
35
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
+ ) => {
37
54
// On some websites, the ids may not exactly match the hash included
38
55
// in the link.
39
56
// For e.g. GitHub will prepend client facing ids with their own
@@ -43,10 +60,8 @@ async function checkLinks() {
43
60
// as being 'user-content-foo-bar' for its own page processing purposes.
44
61
//
45
62
// 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 } ) ;
50
65
else return ids . includes ( hash ) ;
51
66
} ;
52
67
@@ -149,7 +164,15 @@ async function checkLinks() {
149
164
. querySelectorAll ( '[id]' )
150
165
. map ( ( idElement ) => idElement . getAttribute ( 'id' ) ) ;
151
166
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
+ } ;
153
176
} catch ( error ) {
154
177
return {
155
178
errorMessage :
@@ -305,7 +328,9 @@ async function checkLinks() {
305
328
if (
306
329
! isHashCheckingDisabled &&
307
330
hash &&
308
- ! checkPathForHash ( hrefOrSrc , pageData . ids , hash )
331
+ ! checkPathForHash ( hrefOrSrc , pageData . ids , hash , {
332
+ reactPartial : pageData . reactPartial ,
333
+ } )
309
334
) {
310
335
consoleError (
311
336
`Found broken external link on ${ htmlPath } :${ lineNumber } :${ columnNumber } , ` +
0 commit comments