Skip to content

Commit d1aa717

Browse files
committed
Errata: Add support for multiple "subject" links in one item
1 parent 01ee2e2 commit d1aa717

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

11ty/guidelines.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -297,33 +297,39 @@ export const getPrinciplesForVersion = async (version: WcagVersion) =>
297297
export const getErrataForVersion = async (version: WcagVersion) => {
298298
const $ = await loadFromFile(join("errata", `${version}.html`));
299299
const $guidelines = await loadRemoteGuidelines(version, false);
300-
const aSelector = `a[href*='#']:first-of-type`;
300+
const aSelector = `a[href*='}}#']:first-of-type`;
301301
const errata: Record<string, string[]> = {};
302302

303303
$("main > section[id]")
304304
.first()
305305
.find(`li:has(${aSelector})`)
306306
.each((_, el) => {
307307
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-
321308
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]*href="\{\{\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+
});
327333
});
328334

329335
return errata;

0 commit comments

Comments
 (0)