From 8bf3f95995d0fad6bb1fe0bfa18369d98100ed0b 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 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/runtime/index.ts b/src/runtime/index.ts index 7c89c06..b999f6b 100644 --- a/src/runtime/index.ts +++ b/src/runtime/index.ts @@ -44,9 +44,15 @@ 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() + 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);