From 5587011f75064256edcf966fad3c1c5f7579cd93 Mon Sep 17 00:00:00 2001 From: Nikolay Rozhkov Date: Wed, 19 Jun 2024 22:19:50 +0300 Subject: [PATCH 1/3] Fixed wrong elk detector, check only beginning of the line for diagram keywords --- packages/mermaid-flowchart-elk/src/detector.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mermaid-flowchart-elk/src/detector.ts b/packages/mermaid-flowchart-elk/src/detector.ts index 52fb355a55..3b168bd616 100644 --- a/packages/mermaid-flowchart-elk/src/detector.ts +++ b/packages/mermaid-flowchart-elk/src/detector.ts @@ -11,7 +11,7 @@ const detector: DiagramDetector = (txt, config): boolean => { // If diagram explicitly states flowchart-elk /^\s*flowchart-elk/.test(txt) || // If a flowchart/graph diagram has their default renderer set to elk - (/^\s*flowchart|graph/.test(txt) && config?.flowchart?.defaultRenderer === 'elk') + (/^\s*(flowchart|graph)/.test(txt) && config?.flowchart?.defaultRenderer === 'elk') ) { return true; } From 6382dcf7c8f21c469e32eb57aca3732f6dda1b83 Mon Sep 17 00:00:00 2001 From: Nikolay Rozhkov Date: Wed, 19 Jun 2024 22:36:10 +0300 Subject: [PATCH 2/3] Added more specs for elk detector --- .../src/detector.spec.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/mermaid-flowchart-elk/src/detector.spec.ts b/packages/mermaid-flowchart-elk/src/detector.spec.ts index 6e949c57b9..521b4357de 100644 --- a/packages/mermaid-flowchart-elk/src/detector.spec.ts +++ b/packages/mermaid-flowchart-elk/src/detector.spec.ts @@ -39,6 +39,26 @@ describe('flowchart-elk detector', () => { ).toBe(true); }); + // The error from the issue was reproduced with mindmap, so this is just an example + // what matters is the keyword somewhere inside graph definition + it('should check only the beginning of the line in search of keywords', () => { + expect( + detector('mindmap ["Descendant node in flowchart"]', { + flowchart: { + defaultRenderer: 'elk', + }, + }) + ).toBe(false) + + expect( + detector('mindmap ["Descendant node in graph"]', { + flowchart: { + defaultRenderer: 'elk', + }, + }) + ).toBe(false) + }); + it('should detect flowchart-elk', () => { expect(detector('flowchart-elk')).toBe(true); }); From 66cd0b96219ff41e451ce18001d754a26a5180ec Mon Sep 17 00:00:00 2001 From: Nikolay Rozhkov Date: Wed, 19 Jun 2024 22:53:55 +0300 Subject: [PATCH 3/3] Fixed linters --- packages/mermaid-flowchart-elk/src/detector.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mermaid-flowchart-elk/src/detector.spec.ts b/packages/mermaid-flowchart-elk/src/detector.spec.ts index 521b4357de..94ac22d260 100644 --- a/packages/mermaid-flowchart-elk/src/detector.spec.ts +++ b/packages/mermaid-flowchart-elk/src/detector.spec.ts @@ -48,7 +48,7 @@ describe('flowchart-elk detector', () => { defaultRenderer: 'elk', }, }) - ).toBe(false) + ).toBe(false); expect( detector('mindmap ["Descendant node in graph"]', { @@ -56,7 +56,7 @@ describe('flowchart-elk detector', () => { defaultRenderer: 'elk', }, }) - ).toBe(false) + ).toBe(false); }); it('should detect flowchart-elk', () => {