Skip to content

Commit 330630b

Browse files
committed
Use noexport="" to silence some Bikeshed warnings
1 parent 03bfae7 commit 330630b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

wattsi2bikeshed.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ function convert(infile, outfile) {
171171
}
172172
}
173173

174+
// Track used <dfn>s in order to identify the unused ones.
175+
const usedDfns = new Set();
176+
174177
// Replace <span> with the inner <code> or a new <a>.
175178
// TODO: align more closely with Wattsi:
176179
// https://github.com/whatwg/wattsi/blob/b9c28036a2a174f7f87315164f001120596a95f1/src/wattsi.pas#L1454-L1487
@@ -262,6 +265,7 @@ function convert(infile, outfile) {
262265
span.replaceWith(a);
263266

264267
ensureLink(a, dfn);
268+
usedDfns.add(dfn);
265269
}
266270

267271
// Wrap <i data-x="..."> with <a>. Wattsi handling is here:
@@ -284,6 +288,7 @@ function convert(infile, outfile) {
284288
a.appendChild(i);
285289

286290
ensureLink(a, dfn);
291+
usedDfns.add(dfn);
287292
}
288293

289294
for (const code of document.querySelectorAll('pre > code')) {
@@ -355,6 +360,7 @@ function convert(infile, outfile) {
355360
a.appendChild(code);
356361

357362
ensureLink(a, dfn);
363+
usedDfns.add(dfn);
358364
}
359365

360366
// Rewrite data-lt to lt.
@@ -372,6 +378,19 @@ function convert(infile, outfile) {
372378
elem.removeAttribute('data-x-href');
373379
}
374380

381+
// Add noexport to unused <dfn>s to silence Bikeshed warnings about them.
382+
// TODO: vet for cases that are accidentally unused.
383+
for (const dfn of crossRefs.values()) {
384+
if (usedDfns.has(dfn)) {
385+
continue;
386+
}
387+
// This <dfn> is unused by Wattsi rules.
388+
if (dfn.hasAttribute('data-export') || dfn.hasAttribute('export')) {
389+
continue;
390+
}
391+
dfn.setAttribute('noexport', '');
392+
}
393+
375394
// Simplify <a> to Bikeshed autolinks.
376395
for (const a of document.querySelectorAll('a')) {
377396
break;

0 commit comments

Comments
 (0)