Restore fix for divs in links, figure tweak

This commit is contained in:
Will Boyd
2025-04-02 08:57:44 -04:00
parent 8c558cc0a1
commit c92670a5f7
+7 -7
View File
@@ -37,12 +37,12 @@ function initTurndownService() {
});
// <div> within <a> can cause extra whitespace that wreck markdown links, so this removes them
// turndownService.addRule('a', {
// filter: 'a',
// replacement: (content) => {
// return content.replace(/<\/?div[^>]*>/gi, '');
// }
// });
turndownService.addRule('div', {
filter: (node) => {
return node.nodeName === 'DIV' && node.closest('a') !== null;
},
replacement: (content) => content
});
// preserve embedded scripts (for tweets, codepens, gists, etc.)
turndownService.addRule('script', {
@@ -79,7 +79,7 @@ function initTurndownService() {
return result.replace('\n\n\n\n', '\n\n'); // collapse quadruple newlines
} else {
// does not contain <figcaption>, do not preserve
return content;
return '\n' + content + '\n';
}
}
});