Skip to content

Commit 5bab83b

Browse files
authored
Backport fixes for examples in 2.1 recommendation (#4267)
Fixes #2849. This resolves 2 issues: - One example under 5.2.3 missing the leading "Example" text - This was fixed in `main` by #2719, but was incompletely backported - Example numbering in Glossary running on consecutively between definitions - This was fixed in `main` by #3278, but was never backported at all
1 parent 3541a23 commit 5bab83b

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

guidelines/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ <h3>Full pages</h3>
422422
<section id="cc3">
423423
<h3>Complete processes</h3>
424424
<p>When a <a>Web page</a> is one of a series of Web pages presenting a <a>process</a> (i.e., a sequence of steps that need to be completed in order to accomplish an activity), all Web pages in the process conform at the specified level or better. (Conformance is not possible at a particular level if any page in the process does not conform at that level or better.)</p>
425-
<p class="example">An online store has a series of pages that are used to select and purchase products. All pages in the series from start to finish (checkout) conform in order for any page that is part of the process to conform.</p>
425+
<aside class="example"><p>An online store has a series of pages that are used to select and purchase products. All pages in the series from start to finish (checkout) conform in order for any page that is part of the process to conform.</p></aside>
426426
</section>
427427

428428
<!-- This section is quoted in Understanding Conformance. If updated, the update needs to be copied there. -->

script/wcag.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,71 @@ function termTitles() {
8282
});
8383
}
8484

85+
// number notes if there are multiple per section
86+
function numberNotes() {
87+
var sectionsWithNotes = new Array();
88+
document.querySelectorAll(".note").forEach(function(note) {
89+
var container = note.closest("dd");
90+
if (container == null) container = note.closest("section");
91+
sectionsWithNotes.push(container);
92+
});
93+
94+
sectionsWithNotes.forEach(function(sec) {
95+
if (sec.noteprocessed) return;
96+
var notes = sec.querySelectorAll('.note');
97+
// no notes, shouldn't happen
98+
if (notes.length == 0) return;
99+
// one note, leave alone
100+
if (notes.length == 1) return;
101+
// more than one note, number them
102+
if (notes.length > 1) {
103+
var count = 1;
104+
sec.querySelectorAll(".note").forEach(function(note) {
105+
var span = note.querySelector(".note-title span");
106+
span.textContent = "Note " + count;
107+
count++;
108+
});
109+
}
110+
sec.noteprocessed = true;
111+
});
112+
}
113+
114+
// change the numbering of examples to remove number from lone examples in a section, and restart numbering for multiple in each section
115+
function renumberExamples() {
116+
var sectionsWithExamples = new Array();
117+
document.querySelectorAll(".example").forEach(function(example) {
118+
var container = example.closest("dd"); // use dd container if present
119+
if (container == null) container = example.closest("section"); // otherwise section
120+
sectionsWithExamples.push(container);
121+
});
122+
123+
sectionsWithExamples.forEach(function(sec) {
124+
if (sec.exprocessed) return;
125+
var examples = sec.querySelectorAll(".example");
126+
// no examples, shouldn't happen
127+
if (examples.length == 0) return;
128+
// one example, remove the numbering
129+
// more than one example, number them
130+
else {
131+
var count = 1;
132+
var rmOrAdd = examples.length == 1 ? "rm" : "add";
133+
sec.querySelectorAll(".example").forEach(function(example) {
134+
var marker = example.querySelector(".marker");
135+
if (rmOrAdd == "rm") marker.textContent = "Example";
136+
else marker.textContent = "Example " + count;
137+
count++;
138+
});
139+
}
140+
sec.exprocessed = true;
141+
});
142+
}
143+
85144
// scripts after Respec has run
86145
function postRespec() {
87146
addTextSemantics();
88147
swapInDefinitions();
89148
termTitles();
90149
linkUnderstanding();
150+
numberNotes();
151+
renumberExamples();
91152
}

0 commit comments

Comments
 (0)