Skip to content

Commit 7f3d9c7

Browse files
committed
Keep subscript & superscript HTML conditionally
1 parent 469a57b commit 7f3d9c7

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/newTurndownService.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,17 @@ export function newTurndownService(bulletPoint, subBrackets, turndownEscape) {
4444

4545
addRules(t, subBrackets);
4646

47-
t.keep(['u', 'sub', 'sup', 'dl', 'dt', 'dd']);
47+
t.keep(['u', 'dl', 'dt', 'dd']);
48+
49+
// Keep subscript and superscript nodes as HTML if and only if they don't contain
50+
// HTML anchor elements because they are not clickable at least in Obsidian. Also,
51+
// if URLs aren't processed, they can't be made absolute.
52+
t.keep((node) => {
53+
return (
54+
(node.nodeName === 'SUB' || node.nodeName === 'SUP') &&
55+
!node.querySelectorAll('a').length
56+
);
57+
});
4858

4959
t.remove(['style', 'script', 'noscript', 'link']);
5060

0 commit comments

Comments
 (0)