diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow-style.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow-style.spec.js index e05c48627b..3feaa2469e 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow-style.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow-style.spec.js @@ -338,4 +338,20 @@ describe('[Style] when parsing', () => { expect(edges[0].type).toBe('arrow_point'); }); + + it('should handle multiple vertices with style', function () { + const res = flow.parser.parse(` + graph TD + classDef C1 stroke-dasharray:4 + classDef C2 stroke-dasharray:6 + A & B:::C1 & D:::C1 --> E:::C2 + `); + + const vert = flow.parser.yy.getVertices(); + + expect(vert['A'].classes.length).toBe(0); + expect(vert['B'].classes[0]).toBe('C1'); + expect(vert['D'].classes[0]).toBe('C1'); + expect(vert['E'].classes[0]).toBe('C2'); + }); }); diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow.jison b/packages/mermaid/src/diagrams/flowchart/parser/flow.jison index 51427118f7..70fb491625 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow.jison +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow.jison @@ -359,7 +359,7 @@ statement separator: NEWLINE | SEMI | EOF ; - + verticeStatement: verticeStatement link node { /* console.warn('vs',$1.stmt,$3); */ yy.addLink($1.stmt,$3,$2); $$ = { stmt: $3, nodes: $3.concat($1.nodes) } } | verticeStatement link node spaceList @@ -368,12 +368,16 @@ verticeStatement: verticeStatement link node |node { /*console.warn('noda', $1);*/ $$ = {stmt: $1, nodes:$1 }} ; -node: vertex +node: styledVertex { /* console.warn('nod', $1); */ $$ = [$1];} - | node spaceList AMP spaceList vertex + | node spaceList AMP spaceList styledVertex { $$ = $1.concat($5); /* console.warn('pip', $1[0], $5, $$); */ } + ; + +styledVertex: vertex + { /* console.warn('nod', $1); */ $$ = $1;} | vertex STYLE_SEPARATOR idString - {$$ = [$1];yy.setClass($1,$3)} + {$$ = $1;yy.setClass($1,$3)} ; vertex: idString SQS text SQE