mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-19 00:06:47 +02:00
Merge pull request #6796 from HashanCP/bug/6795_fix-flowchart-elk-detector
make flowchart elk detector regex match less greedy
This commit is contained in:
5
.changeset/light-flowers-judge.md
Normal file
5
.changeset/light-flowers-judge.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'mermaid': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: Make flowchart elk detector regex match less greedy
|
@@ -495,4 +495,21 @@ describe('Class diagram', () => {
|
|||||||
cy.get('a').should('have.attr', 'target', '_blank').should('have.attr', 'rel', 'noopener');
|
cy.get('a').should('have.attr', 'target', '_blank').should('have.attr', 'rel', 'noopener');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Include char sequence "graph" in text (#6795)', () => {
|
||||||
|
it('has a label with char sequence "graph"', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
classDiagram
|
||||||
|
class Person {
|
||||||
|
+String name
|
||||||
|
-Int id
|
||||||
|
#double age
|
||||||
|
+Text demographicProfile
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
{ flowchart: { defaultRenderer: 'elk' } }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -354,4 +354,19 @@ ORDER ||--|{ LINE-ITEM : contains
|
|||||||
{ logLevel: 1 }
|
{ logLevel: 1 }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Include char sequence "graph" in text (#6795)', () => {
|
||||||
|
it('has a label with char sequence "graph"', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
erDiagram
|
||||||
|
p[Photograph] {
|
||||||
|
varchar(12) jobId
|
||||||
|
date dateCreated
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
{ flowchart: { defaultRenderer: 'elk' } }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -246,5 +246,22 @@ Word!\`]
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('Include char sequence "graph" in text (#6795)', () => {
|
||||||
|
it('has a label with char sequence "graph"', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
mindmap
|
||||||
|
root
|
||||||
|
Photograph
|
||||||
|
Waterfall
|
||||||
|
Landscape
|
||||||
|
Geography
|
||||||
|
Mountains
|
||||||
|
Rocks
|
||||||
|
`,
|
||||||
|
{ flowchart: { defaultRenderer: 'elk' } }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
/* The end */
|
/* The end */
|
||||||
});
|
});
|
||||||
|
@@ -78,5 +78,41 @@ describe('diagram-orchestration', () => {
|
|||||||
flowchart: 1 "pie" pie: 2 "pie"`)
|
flowchart: 1 "pie" pie: 2 "pie"`)
|
||||||
).toBe('pie');
|
).toBe('pie');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should detect proper diagram when defaultRenderer is elk for flowchart', () => {
|
||||||
|
expect(
|
||||||
|
detectType('mindmap\n root\n Photograph\n Waterfall', {
|
||||||
|
flowchart: { defaultRenderer: 'elk' },
|
||||||
|
})
|
||||||
|
).toBe('mindmap');
|
||||||
|
expect(
|
||||||
|
detectType(
|
||||||
|
`
|
||||||
|
classDiagram
|
||||||
|
class Person {
|
||||||
|
+String name
|
||||||
|
-Int id
|
||||||
|
#double age
|
||||||
|
+Text demographicProfile
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
{ flowchart: { defaultRenderer: 'elk' } }
|
||||||
|
)
|
||||||
|
).toBe('class');
|
||||||
|
expect(
|
||||||
|
detectType(
|
||||||
|
`
|
||||||
|
erDiagram
|
||||||
|
p[Photograph] {
|
||||||
|
varchar(12) jobId
|
||||||
|
date dateCreated
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
{
|
||||||
|
flowchart: { defaultRenderer: 'elk' },
|
||||||
|
}
|
||||||
|
)
|
||||||
|
).toBe('er');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -11,7 +11,7 @@ const detector: DiagramDetector = (txt, config = {}): boolean => {
|
|||||||
// If diagram explicitly states flowchart-elk
|
// If diagram explicitly states flowchart-elk
|
||||||
/^\s*flowchart-elk/.test(txt) ||
|
/^\s*flowchart-elk/.test(txt) ||
|
||||||
// If a flowchart/graph diagram has their default renderer set to elk
|
// 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')
|
||||||
) {
|
) {
|
||||||
config.layout = 'elk';
|
config.layout = 'elk';
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user