From c2a6035f3d9a1f344272fe78fba9c9dc5799ca52 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sat, 31 Jan 2026 16:30:09 +0100 Subject: [PATCH] Improve markdown to HTML conversion by trimming breaks around code blocks --- src/markdown/markdown.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/markdown/markdown.js b/src/markdown/markdown.js index 1b5d9a0..54eb2dc 100644 --- a/src/markdown/markdown.js +++ b/src/markdown/markdown.js @@ -204,6 +204,17 @@ export function markdownToHTML(text) { "$1" ); + // 6.2) Trim breaks around code blocks + html = html + .replace(new RegExp(`${brPattern}\\s*(?=
]*>[\\s\\S]*?<\\/div>)\\s*(?:${brPattern}\\s*)+`, + "g" + ), + "$1" + ); + // 7) Restore code blocks with header + copy button html = html.replace(/@@CODEBLOCK(\d+)@@/g, (_, idx) => { const { lang, code } = codeblocks[+idx];