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