Skip to content

Commit 0e8e03e

Browse files
committed
Handle <i data-x> links
1 parent 017385d commit 0e8e03e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

wattsi2bikeshed.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ function convert(infile, outfile) {
145145
}
146146

147147
// Replace <span> with the inner <code> or a new <a>.
148+
// TODO: align more closely with Wattsi:
149+
// https://github.com/whatwg/wattsi/blob/b9c28036a2a174f7f87315164f001120596a95f1/src/wattsi.pas#L1454-L1487
148150
const spans = document.querySelectorAll('span');
149151
for (const [i, span] of Object.entries(spans)) {
150152
// Don't touch any span with a descendent span.
@@ -231,6 +233,30 @@ function convert(infile, outfile) {
231233
a.appendChild(span.firstChild);
232234
}
233235
span.replaceWith(a);
236+
237+
// TODO: ensure that Bikeshed will identify the same <dfn> as Wattsi.
238+
}
239+
240+
// Wrap <i data-x="..."> with <a>. Wattsi handling is here:
241+
// https://github.com/whatwg/wattsi/blob/b9c28036a2a174f7f87315164f001120596a95f1/src/wattsi.pas#L1454-L1487
242+
for (const i of document.querySelectorAll('i[data-x]')) {
243+
if (i.closest('dfn')) {
244+
continue;
245+
}
246+
247+
const topic = getTopic(i);
248+
const dfn = crossRefs.get(topic);
249+
if (!dfn) {
250+
continue;
251+
// TODO: vet these cases for any that should actually be linked
252+
// console.log(i.outerHTML);
253+
}
254+
255+
const a = document.createElement('a');
256+
i.parentNode.insertBefore(a, i);
257+
a.appendChild(i);
258+
259+
// TODO: ensure that Bikeshed will identify the same <dfn> as Wattsi.
234260
}
235261

236262
for (const code of document.querySelectorAll('pre > code')) {
@@ -300,6 +326,8 @@ function convert(infile, outfile) {
300326
}
301327
code.replaceWith(a);
302328
a.appendChild(code);
329+
330+
// TODO: ensure that Bikeshed will identify the same <dfn> as Wattsi.
303331
}
304332

305333
// Rewrite data-lt to lt.

0 commit comments

Comments
 (0)