@@ -297,33 +297,39 @@ export const getPrinciplesForVersion = async (version: WcagVersion) =>
297
297
export const getErrataForVersion = async ( version : WcagVersion ) => {
298
298
const $ = await loadFromFile ( join ( "errata" , `${ version } .html` ) ) ;
299
299
const $guidelines = await loadRemoteGuidelines ( version , false ) ;
300
- const aSelector = `a[href*='#']:first-of-type` ;
300
+ const aSelector = `a[href*='}} #']:first-of-type` ;
301
301
const errata : Record < string , string [ ] > = { } ;
302
302
303
303
$ ( "main > section[id]" )
304
304
. first ( )
305
305
. find ( `li:has(${ aSelector } )` )
306
306
. each ( ( _ , el ) => {
307
307
const $el = $ ( el ) ;
308
- const $aEl = $el . find ( aSelector ) ;
309
- let hash : string | undefined = $aEl . attr ( "href" ) ! . replace ( / ^ .* # / , "" ) ;
310
-
311
- // Check whether hash pertains to a guideline/SC section or term definition;
312
- // if it doesn't, attempt to resolve it to one
313
- const $hashEl = $guidelines ( `#${ hash } ` ) ;
314
- if ( ! $hashEl . is ( "section.guideline, #terms dfn" ) ) {
315
- const $closest = $hashEl . closest ( "#terms dd, section.guideline" ) ;
316
- if ( $closest . is ( "#terms dd" ) ) hash = $closest . prev ( ) . find ( "dfn[id]" ) . attr ( "id" ) ;
317
- else hash = $closest . attr ( "id" ) ;
318
- }
319
- if ( ! hash ) return ;
320
-
321
308
const erratumHtml = $el
322
- . html ( ) !
323
- . replace ( / ^ .* ?< \/ a > , ? \s * / g, "" )
324
- . replace ( / ^ ( \w ) / , ( _ , p1 ) => p1 . toUpperCase ( ) ) ;
325
- if ( hash in errata ) errata [ hash ] . push ( erratumHtml ) ;
326
- else errata [ hash ] = [ erratumHtml ] ;
309
+ . html ( ) !
310
+ // Remove everything before and including the final TR link
311
+ . replace ( / ^ [ \s \S ] * h r e f = " \{ \{ \s * \w + \s * \} \} # [ \s \S ] * ?< \/ a > , ? \s * / , "" )
312
+ // Remove parenthetical github references (still in Liquid syntax)
313
+ . replace ( / \( \{ % .* % \} \) \s * $ / , "" )
314
+ . replace ( / ^ ( \w ) / , ( _ , p1 ) => p1 . toUpperCase ( ) ) ;
315
+
316
+ $el . find ( aSelector ) . each ( ( _ , aEl ) => {
317
+ const $aEl = $ ( aEl ) ;
318
+ let hash : string | undefined = $aEl . attr ( "href" ) ! . replace ( / ^ .* # / , "" ) ;
319
+
320
+ // Check whether hash pertains to a guideline/SC section or term definition;
321
+ // if it doesn't, attempt to resolve it to one
322
+ const $hashEl = $guidelines ( `#${ hash } ` ) ;
323
+ if ( ! $hashEl . is ( "section.guideline, #terms dfn" ) ) {
324
+ const $closest = $hashEl . closest ( "#terms dd, section.guideline" ) ;
325
+ if ( $closest . is ( "#terms dd" ) ) hash = $closest . prev ( ) . find ( "dfn[id]" ) . attr ( "id" ) ;
326
+ else hash = $closest . attr ( "id" ) ;
327
+ }
328
+ if ( ! hash ) return ;
329
+
330
+ if ( hash in errata ) errata [ hash ] . push ( erratumHtml ) ;
331
+ else errata [ hash ] = [ erratumHtml ] ;
332
+ } ) ;
327
333
} ) ;
328
334
329
335
return errata ;
0 commit comments