From c92670a5f7ad8b8ba7744dd55f8c37374a6ea0de Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Wed, 2 Apr 2025 08:57:44 -0400 Subject: [PATCH] Restore fix for divs in links, figure tweak --- src/translator.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/translator.js b/src/translator.js index ce54c0c..7c4b2c4 100644 --- a/src/translator.js +++ b/src/translator.js @@ -37,12 +37,12 @@ function initTurndownService() { }); //
within 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
, do not preserve - return content; + return '\n' + content + '\n'; } } });