From 45b5b56062562d6dee7f265e4ab3b8c6a4a687ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A2=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BD=D1=86=D0=B5=D0=B2?= Date: Fri, 26 Apr 2024 16:31:30 +0200 Subject: [PATCH] fix: preserve space at the end of diagram code when parsing --- src/runtime/index.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/runtime/index.ts b/src/runtime/index.ts index 7c89c06..52811ad 100644 --- a/src/runtime/index.ts +++ b/src/runtime/index.ts @@ -44,10 +44,13 @@ async function next(): Promise { for (const element of nodesList) { const id = `mermaid-${Date.now()}`; - const content = element.getAttribute('data-content') || ''; - const text = dedent(decodeURIComponent(content)) - .trim() - .replace(//gi, '
'); + const content = decodeURIComponent(element.getAttribute('data-content') || ''); + let dedentedContent = dedent(content); + + if (content.replace(/\n*$/, '').endsWith(' ')) { + dedentedContent += ' '; + } + const text = dedentedContent.trimStart().replace(//gi, '
'); const {svg, bindFunctions} = await mermaid.render(id, text, element); element.innerHTML = svg;