Skip to content

Commit 71809d7

Browse files
committed
Errata: Add support for multiple "subject" links in one item
1 parent 7b2218e commit 71809d7

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
@@ -306,33 +306,39 @@ export const getPrinciplesForVersion = async (version: WcagVersion) =>
306306
export const getErrataForVersion = async (version: WcagVersion) => {
307307
const $ = await loadFromFile(join("errata", `${version}.html`));
308308
const $guidelines = await loadRemoteGuidelines(version, false);
309-
const aSelector = `a[href*='#']:first-of-type`;
309+
const aSelector = `a[href*='}}#']:first-of-type`;
310310
const errata: Record<string, string[]> = {};
311311

312312
$("main > section[id]")
313313
.first()
314314
.find(`li:has(${aSelector})`)
315315
.each((_, el) => {
316316
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-
330317
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]*href="\{\{\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+
});
336342
});
337343

338344
return errata;

0 commit comments

Comments
 (0)