From 52be254ad3b8cd2372b63180702ffce9a141eaa9 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Thu, 14 Aug 2025 16:17:04 +0530 Subject: [PATCH] fix: fallback to raw text instead of rendering empty boxes when `htmlLabels: false` --- .../integration/rendering/flowchart-v2.spec.js | 16 +++++++++++----- .../src/rendering-util/handle-markdown-text.ts | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cypress/integration/rendering/flowchart-v2.spec.js b/cypress/integration/rendering/flowchart-v2.spec.js index bafe40610..6756c433d 100644 --- a/cypress/integration/rendering/flowchart-v2.spec.js +++ b/cypress/integration/rendering/flowchart-v2.spec.js @@ -1165,9 +1165,8 @@ end ); }); - it('should render raw strings for unsuported markdown', () => { - imgSnapshotTest( - `flowchart TB + describe('when rendering unsuported markdown', () => { + const graph = `flowchart TB mermaid{"What is\nyourmermaid version?"} --> v10["<11"] --"\`<**1**1\`"--> fine["No bug"] mermaid --> v11[">= v11"] -- ">= v11" --> broken["Affected by https://github.com/mermaid-js/mermaid/issues/5824"] subgraph subgraph1["\`How to fix **fix**\`"] @@ -1177,7 +1176,14 @@ end githost2["\`Github, Gitlab, BitBucket, etc.\`"] a["1."] b["- x"] - ` - ); + `; + + it('should render raw strings', () => { + imgSnapshotTest(graph); + }); + + it('should render raw strings with htmlLabels: false', () => { + imgSnapshotTest(graph, { htmlLabels: false }); + }); }); }); diff --git a/packages/mermaid/src/rendering-util/handle-markdown-text.ts b/packages/mermaid/src/rendering-util/handle-markdown-text.ts index 82e94c2c2..b20b334f4 100644 --- a/packages/mermaid/src/rendering-util/handle-markdown-text.ts +++ b/packages/mermaid/src/rendering-util/handle-markdown-text.ts @@ -62,6 +62,8 @@ export function markdownToLines(markdown: string, config: MermaidConfig = {}): M }); } else if (treeNode.type === 'html') { lines[currentLine].push({ content: treeNode.text, type: 'normal' }); + } else { + lines[currentLine].push({ content: treeNode.raw, type: 'normal' }); } });