Skip to content

Commit 017385d

Browse files
committed
Handle data-lt in more places
1 parent b140019 commit 017385d

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

wattsi2bikeshed.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,33 @@ function getId(topic) {
7373

7474
// Get the linking text like Bikeshed:
7575
// https://github.com/speced/bikeshed/blob/50d0ec772915adcd5cec0c2989a27fa761d70e71/bikeshed/h/dom.py#L174-L201
76-
function getBikeshedLinkText(elem) {
77-
// Note: ignoring data-lt="" and just looking at text content.
78-
let text;
79-
switch (elem.localName) {
80-
case 'dfn':
81-
case 'a':
82-
text = elem.textContent;
83-
break;
84-
case 'h2':
85-
case 'h3':
86-
case 'h4':
87-
case 'h5':
88-
case 'h6':
89-
text = (elem.querySelector('.content') ?? elem).textContent;
90-
break;
91-
default:
92-
return null;
76+
function getBikeshedLinkTexts(elem) {
77+
const dataLt = elem.getAttribute('data-lt');
78+
if (dataLt === '') {
79+
return [];
80+
}
81+
82+
let texts = [];
83+
if (dataLt) {
84+
// TODO: what's the `rawText in ["|", "||", "|||"]` condition for?
85+
texts = dataLt.split('|');
86+
} else {
87+
switch (elem.localName) {
88+
case 'dfn':
89+
case 'a':
90+
texts = [elem.textContent];
91+
break;
92+
case 'h2':
93+
case 'h3':
94+
case 'h4':
95+
case 'h5':
96+
case 'h6':
97+
texts = [(elem.querySelector('.content') ?? elem).textContent];
98+
break;
99+
}
93100
}
94-
return text.trim().replaceAll(/\s+/g, ' ');
101+
102+
return texts.map((x) => x.trim().replaceAll(/\s+/g, ' '));
95103
}
96104

97105
function convert(infile, outfile) {
@@ -128,10 +136,10 @@ function convert(infile, outfile) {
128136
}
129137

130138
// Remove "new" from the linking text of constructors.
131-
if (dfn.hasAttribute('constructor')) {
132-
const lt = getBikeshedLinkText(dfn);
133-
if (lt.startsWith('new ')) {
134-
dfn.setAttribute('lt', lt.substring(4));
139+
if (dfn.hasAttribute('constructor') && !dfn.hasAttribute('data-lt')) {
140+
const lt = getBikeshedLinkTexts(dfn)[0];
141+
if (lt?.startsWith('new ')) {
142+
dfn.setAttribute('data-lt', lt.substring(4));
135143
}
136144
}
137145
}
@@ -208,6 +216,7 @@ function convert(infile, outfile) {
208216
const value = span.getAttribute(name);
209217
switch (name) {
210218
case 'data-x':
219+
case 'data-lt':
211220
break;
212221
case 'id':
213222
// Copy over.

0 commit comments

Comments
 (0)