mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-01 05:09:34 +02:00
#918 Fix for issue with nodes starting with a number in a subgraph
This commit is contained in:
@@ -38,6 +38,7 @@ const sanitize = text => {
|
||||
* @param classes
|
||||
*/
|
||||
export const addVertex = function (_id, text, type, style, classes) {
|
||||
console.log('called with',_id);
|
||||
let txt
|
||||
let id = _id
|
||||
if (typeof id === 'undefined') {
|
||||
@@ -373,6 +374,9 @@ export const addSubGraph = function (_id, list, _title) {
|
||||
let nodeList = []
|
||||
|
||||
nodeList = uniq(nodeList.concat.apply(nodeList, list))
|
||||
for(let i=0;i<nodeList.length;i++){
|
||||
if(nodeList[i][0].match(/\d/)) nodeList[i] = 's' + nodeList[i];
|
||||
}
|
||||
|
||||
id = id || ('subGraph' + subCount)
|
||||
if (id[0].match(/\d/)) id = 's' + id
|
||||
|
@@ -29,7 +29,7 @@
|
||||
"BT" return 'DIR';
|
||||
"TD" return 'DIR';
|
||||
"BR" return 'DIR';
|
||||
[0-9]+ return 'NUM';
|
||||
[0-9]+ { console.log('got NUM'); return 'NUM';}
|
||||
\# return 'BRKT';
|
||||
":::" return 'STYLE_SEPARATOR';
|
||||
":" return 'COLON';
|
||||
@@ -241,7 +241,7 @@ spaceList
|
||||
|
||||
statement
|
||||
: verticeStatement separator
|
||||
{$$=$1}
|
||||
{ $$=$1}
|
||||
| styleStatement separator
|
||||
{$$=[];}
|
||||
| linkStyleStatement separator
|
||||
@@ -280,11 +280,11 @@ separator: NEWLINE | SEMI | EOF ;
|
||||
// ;
|
||||
|
||||
verticeStatement: verticeStatement link node { yy.addLink($1[0],$3[0],$2); $$ = $3.concat($1) }
|
||||
|node { $$ = $1 }
|
||||
|node { console.log('A node', $1);$$ = $1 }
|
||||
;
|
||||
|
||||
node: vertex
|
||||
{$$ = [$1];}
|
||||
{ console.log('A vertex', $1);$$ = [$1];}
|
||||
| vertex STYLE_SEPARATOR idString
|
||||
{$$ = [$1];yy.setClass($1,$3)}
|
||||
;
|
||||
|
@@ -1414,6 +1414,27 @@ describe('when parsing ', function () {
|
||||
expect(edges.length).toBe(0)
|
||||
expect(vert['id1'].styles.length).toBe(0)
|
||||
})
|
||||
it('should handle a single node with a single digit', function () {
|
||||
// Silly but syntactically correct
|
||||
const res = flow.parser.parse('graph TD;1;')
|
||||
|
||||
const vert = flow.parser.yy.getVertices()
|
||||
const edges = flow.parser.yy.getEdges()
|
||||
|
||||
expect(edges.length).toBe(0)
|
||||
expect(vert['s1'].text).toBe('1')
|
||||
})
|
||||
it('should handle a single node with a single digit in a subgraph', function () {
|
||||
// Silly but syntactically correct
|
||||
|
||||
const res = flow.parser.parse('graph TD;subgraph "hello";1;end;')
|
||||
|
||||
const vert = flow.parser.yy.getVertices()
|
||||
const edges = flow.parser.yy.getEdges()
|
||||
|
||||
expect(edges.length).toBe(0)
|
||||
expect(vert['s1'].text).toBe('1')
|
||||
})
|
||||
it('should handle a single node with alphanumerics starting on a num', function () {
|
||||
// Silly but syntactically correct
|
||||
const res = flow.parser.parse('graph TD;1id;')
|
||||
|
Reference in New Issue
Block a user