Skip to content

Commit e4d2546

Browse files
Merge branch 'main' into giacomo-petri-3_3_2-non-text-label
2 parents ab865b6 + 81eb4b3 commit e4d2546

File tree

295 files changed

+2777
-2482
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

295 files changed

+2777
-2482
lines changed

.eleventyignore

Lines changed: 0 additions & 29 deletions
This file was deleted.

11ty/CustomLiquid.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { type Options as SlugifyOptions, slugifyWithCounter } from "@sindresorhus/slugify";
2+
import hljs from "highlight.js";
13
import { Liquid, type Template } from "liquidjs";
24
import type { LiquidOptions, RenderOptions } from "liquidjs/dist/liquid-options";
35
import compact from "lodash-es/compact";
@@ -9,7 +11,6 @@ import type { GlobalData } from "eleventy.config";
911

1012
import { biblioPattern, getBiblio, getXmlBiblio } from "./biblio";
1113
import { flattenDom, load, type CheerioAnyNode } from "./cheerio";
12-
import { generateId } from "./common";
1314
import { getAcknowledgementsForVersion, type TermsMap } from "./guidelines";
1415
import { resolveTechniqueIdFromHref, understandingToTechniqueLinkSelector } from "./techniques";
1516
import { techniqueToUnderstandingLinkSelector } from "./understanding";
@@ -153,6 +154,31 @@ export class CustomLiquid extends Liquid {
153154
// Add charset to pages that forgot it
154155
if (!$("meta[charset]").length) $('<meta charset="UTF-8">').prependTo("head");
155156

157+
const $missingHljsOverrides = $("pre code:not([class])");
158+
if ($missingHljsOverrides.length) {
159+
$missingHljsOverrides.each((_, el) => {
160+
const code = $(el).html()!.replace(/\n/g, "\\n");
161+
const excerpt = `${code.slice(0, 40)}${code.length > 40 ? "..." : ""}`;
162+
console.log(
163+
`${filepath} missing "language-*" or "no-highlight" class on <pre><code> starting with ${excerpt}`
164+
);
165+
});
166+
if (process.env.ELEVENTY_RUN_MODE === "build") {
167+
throw new Error(
168+
"Please ensure all code blocks have a highlight.js class (language-* or no-highlight)."
169+
);
170+
}
171+
}
172+
173+
$("pre code[class*='language-']").each((_, el) => {
174+
const $el = $(el);
175+
// Unescape any HTML entities (which were originally needed for client-side highlight.js)
176+
const code = $el.html()!.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
177+
const language = $el.attr("class")!.replace(/^.*language-(\S+).*$/, "$1");
178+
$el.html(hljs.highlight(code, { language }).value);
179+
$el.addClass("hljs");
180+
});
181+
156182
const prependedIncludes = ["header"];
157183
const appendedIncludes = ["wai-site-footer", "site-footer"];
158184

@@ -614,6 +640,9 @@ export class CustomLiquid extends Liquid {
614640
} else $("section#references").remove();
615641
}
616642

643+
const slugify = slugifyWithCounter();
644+
const slugifyOptions: SlugifyOptions = { decamelize: false };
645+
617646
// Allow autogenerating missing top-level section IDs in understanding docs,
618647
// but don't pick up incorrectly-nested sections in some techniques pages (e.g. H91)
619648
const sectionSelector = scope.isUnderstanding ? "section" : "section[id]:not(.obsolete)";
@@ -624,7 +653,8 @@ export class CustomLiquid extends Liquid {
624653
// when we have sections and sidebar skeleton already reordered
625654
const $tocList = $(".sidebar nav ul");
626655
$h2Sections.each((_, el) => {
627-
if (!el.attribs.id) el.attribs.id = generateId($(el).find(sectionH2Selector).text());
656+
if (!el.attribs.id)
657+
el.attribs.id = slugify($(el).find(sectionH2Selector).text(), slugifyOptions);
628658
$("<a></a>")
629659
.attr("href", `#${el.attribs.id}`)
630660
.text(normalizeTocLabel($(el).find(sectionH2Selector).text()))
@@ -648,9 +678,14 @@ export class CustomLiquid extends Liquid {
648678
$(autoIdSectionSelectors.join(", "))
649679
.filter(`:has(${sectionHeadingSelector})`)
650680
.each((_, el) => {
651-
el.attribs.id = generateId($(el).find(sectionHeadingSelector).text());
681+
el.attribs.id = slugify($(el).find(sectionHeadingSelector).text(), slugifyOptions);
652682
});
653683

684+
// Also autogenerate IDs for any headings with no dedicated section nor explicit ID
685+
$(":is(h3, h4, h5):not(:first-child):not([id])").each((_, el) => {
686+
el.attribs.id = slugify($(el).text(), slugifyOptions);
687+
});
688+
654689
return stripHtmlComments($.html());
655690
}
656691
}

11ty/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ Generates `_site/wcag.json`. (This is not done by default, as it adds to build t
183183

184184
**Default:** Unset by default; `publish-w3c` scripts set this to a non-empty value.
185185

186+
For more information on the output, see [11ty/json/README.md](json#readme).
187+
186188
### `GITHUB_REPOSITORY`
187189

188190
**Usage context:** Automatically set during GitHub workflows; should not need to be set manually

11ty/json/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# JSON Serialization of WCAG 2
2+
3+
The script in this folder serializes WCAG 2 information into JSON format, including:
4+
5+
- Principles, guidelines, and success criteria
6+
- Glossary terms
7+
- Associations between (normative) success criteria and (informative) techniques
8+
9+
The following JSON files are published monthly:
10+
11+
- [WCAG 2.2 JSON](https://www.w3.org/WAI/WCAG22/wcag.json)
12+
- [WCAG 2.1 JSON](https://www.w3.org/WAI/WCAG21/wcag.json)
13+
14+
For a history of structural changes to the JSON files, see the [list of merged wcag.json pull requests](https://github.com/w3c/wcag/pulls?q=is%3Apr+label%3Awcag.json), and in particular the "wcag.json Changes" section in each pull request description.
15+
16+
## Permission to use with attribution
17+
18+
You may use this data, in full or in part, provided you:
19+
20+
- Clearly attribute the original source and include a link to it ([Web Content Accessibility Guidelines (WCAG) 2.2](https://www.w3.org/TR/WCAG22/), [Techniques for WCAG 2.2](https://www.w3.org/WAI/WCAG22/Techniques/), [Web Content Accessibility Guidelines (WCAG) 2.1](https://www.w3.org/TR/WCAG21/), [Techniques for WCAG 2.1](https://www.w3.org/WAI/WCAG21/Techniques/))
21+
- Do not change the content
22+
23+
If you include additional information, it must be clear what is from the W3C WCAG documents and what is added.
24+
25+
See [W3C Document license](https://www.w3.org/copyright/document-license/) and [W3C Intellectual rights](https://www.w3.org/copyright/intellectual-rights/), particularly '[May I annotate one of your specifications?](https://www.w3.org/copyright/intellectual-rights/#annotate)'.

0 commit comments

Comments
 (0)