8000 Linkify the specification (#765) · unicode-org/message-format-wg@a31b053 · GitHub
[go: up one dir, main page]

Skip to content

Commit a31b053

Browse files
authored
Linkify the specification (#765)
* Linkify the specification This wasn't done in time for the LDML45 release, but capturing it publicly for later implementation. Can be added to the `tr35-messageformat.html` file. * Fix irregular plurals bidi isolation _strategies_ 😉 Also added a bit of debugging gorp * Prettier * Cleanup Thanks to @eemeli * Refactor to make a single function do the work Eliminates globals and does all the work in `linkify`
1 parent d83b098 commit a31b053

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

docs/tools/linkify.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Work in progress: tooling to linkify the HTML produced from
2+
// the MessageFormat 2 markdown.
3+
// this has been tested on the tr35-messageformat.html file
4+
// but not implemented in LDML45
5+
function linkify() {
6+
const terms = findTerms();
7+
const missing = new Set();
8+
const links = document.querySelectorAll("em");
9+
links.forEach((item) => {
10+
const target = generateId(item.textContent);
11+
if (terms.has(target)) {
12+
const el = item.lastElementChild ?? item;
13+
el.innerHTML = `<a href="#${target}">${item.textContent}</a>`;
14+
} else {
15+
missing.add(target);
16+
}
17+
});
18+
// report missing terms
19+
// (leave out sort if you want it in file order)
20+
Array.from(missing).sort().forEach((item)=> {
21+
console.log(item);
22+
});
23+
}
24+
25+
function findTerms() {
26+
const terms = new Set();
27+
document.querySelectorAll("dfn").forEach((item) => {
28+
// console.log(index + ": " + item.textContent);
29+
const term = generateId(item.textContent);
30+
// guard against duplicates
31+
if (terms.has(term)) {
32+
console.log("Duplicate term: " + term);
33+
}
34+
terms.add(term);
35+
item.setAttribute("id", term);
36+
});
37+
return terms;
38+
}
39+
40+
function generateId(term) {
41+
const id = term.toLowerCase().replaceAll(" ", "-");
42+
if (id.endsWith("rategies")) {
43+
// found in the bidi isolation strategies
44+
return id.slice(0, -3) + "y";
45+
} else if (id.endsWith("s") && id !== "status") {
46+
// regular English plurals
47+
return id.slice(0, -1);
48+
}
49+
return id;
50+
}

0 commit comments

Comments
 (0)
0