mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-23 16:04:12 +02:00
Compare commits
5 Commits
renovate/m
...
bug/2492-f
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8127d01db7 | ||
![]() |
3ac107508b | ||
![]() |
c3bf04b72e | ||
![]() |
279c62af72 | ||
![]() |
81d00bd4e4 |
@@ -1 +1 @@
|
|||||||
./packages/mermaid/CHANGELOG.md
|
./packages/mermaid/CHANGELOG.md
|
||||||
|
@@ -1 +1 @@
|
|||||||
./packages/mermaid/src/docs/community/contributing.md
|
./packages/mermaid/src/docs/community/contributing.md
|
||||||
|
10
package.json
10
package.json
@@ -67,7 +67,7 @@
|
|||||||
"@argos-ci/cypress": "^6.1.3",
|
"@argos-ci/cypress": "^6.1.3",
|
||||||
"@changesets/changelog-github": "^0.5.1",
|
"@changesets/changelog-github": "^0.5.1",
|
||||||
"@changesets/cli": "^2.29.7",
|
"@changesets/cli": "^2.29.7",
|
||||||
"@cspell/eslint-plugin": "^9.2.2",
|
"@cspell/eslint-plugin": "^8.19.4",
|
||||||
"@cypress/code-coverage": "^3.14.6",
|
"@cypress/code-coverage": "^3.14.6",
|
||||||
"@eslint/js": "^9.26.0",
|
"@eslint/js": "^9.26.0",
|
||||||
"@rollup/plugin-typescript": "^12.1.4",
|
"@rollup/plugin-typescript": "^12.1.4",
|
||||||
@@ -95,16 +95,16 @@
|
|||||||
"esbuild": "^0.25.10",
|
"esbuild": "^0.25.10",
|
||||||
"eslint": "^9.26.0",
|
"eslint": "^9.26.0",
|
||||||
"eslint-config-prettier": "^10.1.8",
|
"eslint-config-prettier": "^10.1.8",
|
||||||
"eslint-plugin-cypress": "^5.2.0",
|
"eslint-plugin-cypress": "^4.3.0",
|
||||||
"eslint-plugin-html": "^8.1.3",
|
"eslint-plugin-html": "^8.1.3",
|
||||||
"eslint-plugin-jest": "^29.0.1",
|
"eslint-plugin-jest": "^28.14.0",
|
||||||
"eslint-plugin-jsdoc": "^61.1.5",
|
"eslint-plugin-jsdoc": "^50.8.0",
|
||||||
"eslint-plugin-json": "^4.0.1",
|
"eslint-plugin-json": "^4.0.1",
|
||||||
"eslint-plugin-lodash": "^8.0.0",
|
"eslint-plugin-lodash": "^8.0.0",
|
||||||
"eslint-plugin-markdown": "^5.1.0",
|
"eslint-plugin-markdown": "^5.1.0",
|
||||||
"eslint-plugin-no-only-tests": "^3.3.0",
|
"eslint-plugin-no-only-tests": "^3.3.0",
|
||||||
"eslint-plugin-tsdoc": "^0.4.0",
|
"eslint-plugin-tsdoc": "^0.4.0",
|
||||||
"eslint-plugin-unicorn": "^61.0.2",
|
"eslint-plugin-unicorn": "^59.0.1",
|
||||||
"express": "^5.1.0",
|
"express": "^5.1.0",
|
||||||
"globals": "^16.4.0",
|
"globals": "^16.4.0",
|
||||||
"globby": "^14.1.0",
|
"globby": "^14.1.0",
|
||||||
|
@@ -266,4 +266,156 @@ describe('[Arrows] when parsing', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Issue #2492: Node names starting with o/x should not be consumed by arrow markers', () => {
|
||||||
|
it('should handle node names starting with "o" after plain arrows', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\ndev---ops;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('dev').id).toBe('dev');
|
||||||
|
expect(vert.get('ops').id).toBe('ops');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('dev');
|
||||||
|
expect(edges[0].end).toBe('ops');
|
||||||
|
expect(edges[0].type).toBe('arrow_open');
|
||||||
|
expect(edges[0].stroke).toBe('normal');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle node names starting with "x" after plain arrows', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\ndev---xerxes;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('dev').id).toBe('dev');
|
||||||
|
expect(vert.get('xerxes').id).toBe('xerxes');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('dev');
|
||||||
|
expect(edges[0].end).toBe('xerxes');
|
||||||
|
expect(edges[0].type).toBe('arrow_open');
|
||||||
|
expect(edges[0].stroke).toBe('normal');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should still support circle arrows with spaces', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\nA --o B;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('A').id).toBe('A');
|
||||||
|
expect(vert.get('B').id).toBe('B');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('A');
|
||||||
|
expect(edges[0].end).toBe('B');
|
||||||
|
expect(edges[0].type).toBe('arrow_circle');
|
||||||
|
expect(edges[0].stroke).toBe('normal');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should still support cross arrows with spaces', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\nC --x D;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('C').id).toBe('C');
|
||||||
|
expect(vert.get('D').id).toBe('D');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('C');
|
||||||
|
expect(edges[0].end).toBe('D');
|
||||||
|
expect(edges[0].type).toBe('arrow_cross');
|
||||||
|
expect(edges[0].stroke).toBe('normal');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should support circle arrows to uppercase nodes without spaces', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\nA--oB;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('A').id).toBe('A');
|
||||||
|
expect(vert.get('B').id).toBe('B');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('A');
|
||||||
|
expect(edges[0].end).toBe('B');
|
||||||
|
expect(edges[0].type).toBe('arrow_circle');
|
||||||
|
expect(edges[0].stroke).toBe('normal');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should support cross arrows to uppercase nodes without spaces', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\nA--xBar;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('A').id).toBe('A');
|
||||||
|
expect(vert.get('Bar').id).toBe('Bar');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('A');
|
||||||
|
expect(edges[0].end).toBe('Bar');
|
||||||
|
expect(edges[0].type).toBe('arrow_cross');
|
||||||
|
expect(edges[0].stroke).toBe('normal');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle thick arrows with lowercase node names starting with "o"', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\nalpha===omega;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('alpha').id).toBe('alpha');
|
||||||
|
expect(vert.get('omega').id).toBe('omega');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('alpha');
|
||||||
|
expect(edges[0].end).toBe('omega');
|
||||||
|
expect(edges[0].type).toBe('arrow_open');
|
||||||
|
expect(edges[0].stroke).toBe('thick');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle dotted arrows with lowercase node names starting with "o"', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\nfoo-.-opus;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('foo').id).toBe('foo');
|
||||||
|
expect(vert.get('opus').id).toBe('opus');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('foo');
|
||||||
|
expect(edges[0].end).toBe('opus');
|
||||||
|
expect(edges[0].type).toBe('arrow_open');
|
||||||
|
expect(edges[0].stroke).toBe('dotted');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should still support dotted circle arrows with spaces', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\nB -.-o C;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('B').id).toBe('B');
|
||||||
|
expect(vert.get('C').id).toBe('C');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('B');
|
||||||
|
expect(edges[0].end).toBe('C');
|
||||||
|
expect(edges[0].type).toBe('arrow_circle');
|
||||||
|
expect(edges[0].stroke).toBe('dotted');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should still support thick cross arrows with spaces', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\nC ==x D;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('C').id).toBe('C');
|
||||||
|
expect(vert.get('D').id).toBe('D');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('C');
|
||||||
|
expect(edges[0].end).toBe('D');
|
||||||
|
expect(edges[0].type).toBe('arrow_cross');
|
||||||
|
expect(edges[0].stroke).toBe('thick');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -0,0 +1,129 @@
|
|||||||
|
import { describe, it, expect, beforeEach } from 'vitest';
|
||||||
|
import flow from './flowParser.js';
|
||||||
|
import { FlowDB } from '../flowDb.js';
|
||||||
|
|
||||||
|
describe('Flowchart arrow parsing - Issue #2492', () => {
|
||||||
|
let flowDb: FlowDB;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
flowDb = new FlowDB();
|
||||||
|
flow.parser.yy = flowDb;
|
||||||
|
flowDb.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Solid arrows with markers', () => {
|
||||||
|
it('should parse --> followed by uppercase node', () => {
|
||||||
|
const diagram = 'graph TD\nA-->B';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse --> followed by lowercase node', () => {
|
||||||
|
const diagram = 'graph TD\nA-->b';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse --> followed by space', () => {
|
||||||
|
const diagram = 'graph TD\nA--> B';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse --- followed by uppercase node (issue #2492)', () => {
|
||||||
|
const diagram = 'graph TD\ndev---Ops';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse --- followed by lowercase node (issue #2492)', () => {
|
||||||
|
const diagram = 'graph TD\ndev---ops';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse --o followed by uppercase node', () => {
|
||||||
|
const diagram = 'graph TD\nA--oB';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse --o followed by lowercase node', () => {
|
||||||
|
const diagram = 'graph TD\nA--ob';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse --x followed by uppercase node', () => {
|
||||||
|
const diagram = 'graph TD\nA--xBar';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse --x followed by lowercase node', () => {
|
||||||
|
const diagram = 'graph TD\nA--xbar';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Thick arrows with markers', () => {
|
||||||
|
it('should parse ==> followed by uppercase node', () => {
|
||||||
|
const diagram = 'graph TD\nA==>B';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse ==> followed by lowercase node', () => {
|
||||||
|
const diagram = 'graph TD\nA==>b';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse === followed by lowercase node', () => {
|
||||||
|
const diagram = 'graph TD\nA===b';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Dotted arrows with markers', () => {
|
||||||
|
it('should parse -.-> followed by uppercase node', () => {
|
||||||
|
const diagram = 'graph TD\nA-.->B';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse -.-> followed by lowercase node', () => {
|
||||||
|
const diagram = 'graph TD\nA-.->b';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse -.- followed by lowercase node', () => {
|
||||||
|
const diagram = 'graph TD\nA-.-b';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Arrows with edge text', () => {
|
||||||
|
it('should parse arrow with edge text followed by uppercase node', () => {
|
||||||
|
const diagram = 'graph TD\nA-->|text|B';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse arrow with edge text followed by lowercase node', () => {
|
||||||
|
const diagram = 'graph TD\nA-->|text|b';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse multiple arrows with edge text (regression test)', () => {
|
||||||
|
const diagram = 'graph TD\nA-->|Get money|B\nB-->C\nC-->|One|D\nC-->|Two|E';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Arrows followed by digits', () => {
|
||||||
|
it('should parse --> followed by digit', () => {
|
||||||
|
const diagram = 'graph LR\n47-->48';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse --> followed by node starting with digit', () => {
|
||||||
|
const diagram = 'graph LR\nA-->48(Node)';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse complex diagram with digit node IDs (Sample 4)', () => {
|
||||||
|
const diagram =
|
||||||
|
'graph LR\n47(SAM.CommonFA.FMESummary)-->48(SAM.CommonFA.CommonFAFinanceBudget)\n37(SAM.CommonFA.BudgetSubserviceLineVolume)-->48(SAM.CommonFA.CommonFAFinanceBudget)';
|
||||||
|
expect(() => flow.parser.parse(diagram)).not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@@ -152,17 +152,29 @@ that id.
|
|||||||
"," return 'COMMA';
|
"," return 'COMMA';
|
||||||
"*" return 'MULT';
|
"*" return 'MULT';
|
||||||
|
|
||||||
<INITIAL,edgeText>\s*[xo<]?\-\-+[-xo>]\s* { this.popState(); return 'LINK'; }
|
<INITIAL,edgeText>\s*[xo<]?\-\-+[-xo>]\s+ { this.popState(); return 'LINK'; }
|
||||||
<INITIAL>\s*[xo<]?\-\-\s* { this.pushState("edgeText"); return 'START_LINK'; }
|
<INITIAL>\s*[xo<]?\-\-+[-xo>](?=[A-Z]) { return 'LINK'; }
|
||||||
<edgeText>[^-]|\-(?!\-)+ return 'EDGE_TEXT';
|
<INITIAL>\s*[xo<]?\-\-+[-xo>](?=[a-z]) { return 'LINK'; }
|
||||||
|
<INITIAL>\s*[xo<]?\-\-+[-xo>](?=[0-9]) { return 'LINK'; }
|
||||||
|
<INITIAL,edgeText>\s*[xo<]?\-\-+[-xo>](?=\s*\|) { this.popState(); return 'LINK'; }
|
||||||
|
<INITIAL>\s*[xo<]?\-\-\s* { this.pushState("edgeText"); return 'START_LINK'; }
|
||||||
|
<edgeText>[^-]|\-(?!\-)+ return 'EDGE_TEXT';
|
||||||
|
|
||||||
<INITIAL,thickEdgeText>\s*[xo<]?\=\=+[=xo>]\s* { this.popState(); return 'LINK'; }
|
<INITIAL,thickEdgeText>\s*[xo<]?\=\=+[=xo>]\s+ { this.popState(); return 'LINK'; }
|
||||||
<INITIAL>\s*[xo<]?\=\=\s* { this.pushState("thickEdgeText"); return 'START_LINK'; }
|
<INITIAL>\s*[xo<]?\=\=+[=xo>](?=[A-Z]) { return 'LINK'; }
|
||||||
<thickEdgeText>[^=]|\=(?!=) return 'EDGE_TEXT';
|
<INITIAL>\s*[xo<]?\=\=+[=xo>](?=[a-z]) { return 'LINK'; }
|
||||||
|
<INITIAL>\s*[xo<]?\=\=+[=xo>](?=[0-9]) { return 'LINK'; }
|
||||||
|
<INITIAL,thickEdgeText>\s*[xo<]?\=\=+[=xo>](?=\s*\|) { this.popState(); return 'LINK'; }
|
||||||
|
<INITIAL>\s*[xo<]?\=\=\s* { this.pushState("thickEdgeText"); return 'START_LINK'; }
|
||||||
|
<thickEdgeText>[^=]|\=(?!=) return 'EDGE_TEXT';
|
||||||
|
|
||||||
<INITIAL,dottedEdgeText>\s*[xo<]?\-?\.+\-[xo>]?\s* { this.popState(); return 'LINK'; }
|
<INITIAL,dottedEdgeText>\s*[xo<]?\-?\.+\-[xo>]?\s+ { this.popState(); return 'LINK'; }
|
||||||
<INITIAL>\s*[xo<]?\-\.\s* { this.pushState("dottedEdgeText"); return 'START_LINK'; }
|
<INITIAL>\s*[xo<]?\-?\.+\-[xo>]?(?=[A-Z]) { return 'LINK'; }
|
||||||
<dottedEdgeText>[^\.]|\.(?!-) return 'EDGE_TEXT';
|
<INITIAL>\s*[xo<]?\-?\.+\-[xo>]?(?=[a-z]) { return 'LINK'; }
|
||||||
|
<INITIAL>\s*[xo<]?\-?\.+\-[xo>]?(?=[0-9]) { return 'LINK'; }
|
||||||
|
<INITIAL,dottedEdgeText>\s*[xo<]?\-?\.+\-[xo>]?(?=\s*\|) { this.popState(); return 'LINK'; }
|
||||||
|
<INITIAL>\s*[xo<]?\-\.\s* { this.pushState("dottedEdgeText"); return 'START_LINK'; }
|
||||||
|
<dottedEdgeText>[^\.]|\.(?!-) return 'EDGE_TEXT';
|
||||||
|
|
||||||
|
|
||||||
<*>\s*\~\~[\~]+\s* return 'LINK';
|
<*>\s*\~\~[\~]+\s* return 'LINK';
|
||||||
|
613
pnpm-lock.yaml
generated
613
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user