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;