Skip to content

Commit c054671

Browse files
committed
convert inline codes as markdown
1 parent 6821602 commit c054671

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/idlfetcher.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ function processComments(dom: DocumentFragment) {
103103
for (const {dt, dd} of generateDescriptionPairs(element)) {
104104
elements.push(...importNestedList(dd));
105105
const comment = dd
106-
.map(desc => getCommentText(innerText(desc)))
106+
.map(desc => {
107+
desc.normalize();
108+
convertChildPre(desc);
109+
return getCommentText(innerText(desc))
110+
})
111+
.filter(text => text)
107112
.join("\n\n");
108113
for (const key of dt.map(term => getKey(term.innerHTML))) {
109114
if (!key) {
@@ -123,6 +128,21 @@ function processComments(dom: DocumentFragment) {
123128
return JSON.stringify(result, undefined, 4);
124129
}
125130

131+
function convertChildPre(e: Element) {
132+
for (const pre of e.querySelectorAll("pre")) {
133+
const code = pre.querySelector(":scope > code") as HTMLElement;
134+
if (!code) {
135+
continue;
136+
}
137+
const text = innerText(code, {
138+
getComputedStyle(_: Element) {
139+
return { whiteSpace: "pre" } as CSSStyleDeclaration;
140+
}
141+
});
142+
pre.textContent = "```\n" + text + "\n```";
143+
}
144+
}
145+
126146
function getKey(s: string) {
127147
const keyRegexp = /#dom-([a-zA-Z0-9-_]+)/i;
128148
const match = s.match(keyRegexp);

0 commit comments

Comments
 (0)