Skip to content

Commit

Permalink
fix: preserve space at the end of diagram code when parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
smsochneg committed Apr 26, 2024
1 parent d10a72c commit 45b5b56
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ async function next(): Promise<void> {

for (const element of nodesList) {
const id = `mermaid-${Date.now()}`;
const content = element.getAttribute('data-content') || '';
const text = dedent(decodeURIComponent(content))
.trim()
.replace(/<br\s*\/?>/gi, '<br/>');
const content = decodeURIComponent(element.getAttribute('data-content') || '');
let dedentedContent = dedent(content);

if (content.replace(/\n*$/, '').endsWith(' ')) {
dedentedContent += ' ';
}
const text = dedentedContent.trimStart().replace(/<br\s*\/?>/gi, '<br/>');

const {svg, bindFunctions} = await mermaid.render(id, text, element);
element.innerHTML = svg;
Expand Down

0 comments on commit 45b5b56

Please sign in to comment.