From 648070e4ac757f6096f595bd564752e705d68c22 Mon Sep 17 00:00:00 2001 From: smsochneg Date: Sun, 28 Apr 2024 01:06:08 +0200 Subject: [PATCH] fix: preserve space at the end of diagram code when parsing (#17) --- 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;