From ef22a899d49b9a31ca5b08e6d3d91f1c48674bdc Mon Sep 17 00:00:00 2001 From: Ashish Jain Date: Wed, 17 Sep 2025 15:36:04 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Fix=20markdown=20formatting=20in=20?= =?UTF-8?q?subgraphs=20(98.6%=20pass=20rate)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed subgraph title type detection for markdown vs text - Resolved timing issue with stack initialization - Pass rate: 98.5% → 98.6% (+0.1%) - Remaining: 4 failing tests to reach 99.7% target Test results: - subgraph "One" → labelType: 'text' ✅ - subgraph "`**Two**`" → labelType: 'markdown' ✅ --- .../flowchart/parser/antlr/FlowchartParserCore.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/mermaid/src/diagrams/flowchart/parser/antlr/FlowchartParserCore.ts b/packages/mermaid/src/diagrams/flowchart/parser/antlr/FlowchartParserCore.ts index d8aad49c5..381d6822b 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/antlr/FlowchartParserCore.ts +++ b/packages/mermaid/src/diagrams/flowchart/parser/antlr/FlowchartParserCore.ts @@ -86,8 +86,7 @@ export class FlowchartParserCore { // Subgraph processing methods protected processSubgraphStatement(id: string, title?: string): void { - // Push default title type for new subgraph (will be updated during title processing) - this.subgraphTitleTypeStack.push('text'); + // Stack is already initialized in processSubgraphStatementCore before title extraction const subgraphData = { id: id, @@ -1254,6 +1253,9 @@ export class FlowchartParserCore { protected processSubgraphStatementCore(ctx: any): void { console.log('🔍 FlowchartParser: Processing subgraph statement'); + // Initialize the stack BEFORE extracting the title so title processing can update it + this.subgraphTitleTypeStack.push('text'); + const extractedId = this.extractSubgraphId(ctx); const title = this.extractSubgraphLabel(ctx); @@ -1385,7 +1387,7 @@ export class FlowchartParserCore { } // Check for regular quoted strings: "content" else if (text.match(/^"[^"]*"$/)) { - type = 'string'; + type = 'text'; // Regular quoted strings should be 'text', not 'string' const match = text.match(/^"([^"]*)"$/); if (match) { text = match[1]; @@ -1397,8 +1399,10 @@ export class FlowchartParserCore { text = text.slice(1, -1); // Remove backticks } - // Store the type information for later use in processSubgraphEnd - this.lastSubgraphTitleType = type; + // Update the current subgraph's title type in the stack + if (this.subgraphTitleTypeStack.length > 0) { + this.subgraphTitleTypeStack[this.subgraphTitleTypeStack.length - 1] = type; + } console.log('🔍 Subgraph title: stored type:', type, 'text:', text); return text; }