Improve markdown to HTML conversion by trimming breaks around code blocks

This commit is contained in:
2026-01-31 16:30:09 +01:00
parent fa8d2807e8
commit c2a6035f3d

View File

@@ -204,6 +204,17 @@ export function markdownToHTML(text) {
"$1"
);
// 6.2) Trim breaks around code blocks
html = html
.replace(new RegExp(`${brPattern}\\s*(?=<div class="md-codeblock"\\b)`, "g"), "")
.replace(
new RegExp(
`(<div class="md-codeblock"[^>]*>[\\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];