-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.js
More file actions
48 lines (46 loc) · 1.6 KB
/
Copy pathexamples.js
File metadata and controls
48 lines (46 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function numberExamples() {
console.log("Numbering examples")
var examples = document.querySelectorAll("li.example");
var exrefs = document.querySelectorAll("a.exref");
for (var exc = 0; exc < examples.length; exc++) {
ex = examples[exc]
ex.setAttribute("value", exc + 1)
var subexamplesol = ex.querySelector("ol.subexample");
if (subexamplesol) {
subexamples = subexamplesol.children
for (var subexc = 0; subexc < subexamples.length; subexc++) {
subexamples[subexc].setAttribute("value", subexc + 1)
}
}
}
exrefs.forEach(function(x, i) {
example_id = x.getAttribute("example_id")
x.setAttribute("href", "#" + example_id)
if (!x.hasAttribute("bare")) {
x.textContent += "("
}
x.textContent += get_example_marker(example_id)
if (x.hasAttribute("end")) {
end = x.getAttribute("end")
x.textContent += "-" + get_example_marker(end)
}
if (x.hasAttribute("suffix")) {
x.textContent += x.getAttribute("suffix")
}
if (!x.hasAttribute("bare")) {
x.textContent += ")"
}
});
}
function get_example_marker(example_id) {
ex = document.getElementById(example_id)
if (ex != null) {
parent = ex.parentElement
if (parent.getAttribute("class") == "subexample") {
return parent.parentElement.value + String.fromCharCode(96 + ex.value)
}
return ex.value
} else {
console.log("Can't find example with the ID " + example_id)
}
}