#918 Fix for issue with nodes starting with a number in a subgraph

This commit is contained in:
knsv 2019-09-01 00:44:48 -07:00
parent 27d0b934a1
commit 699bd61045
26 changed files with 63 additions and 4 deletions

View File

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Mermaid Quick Test Page</title>
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgo=">
<style>
body {
font-family: 'trebuchet ms', verdana, arial;
}
</style>
</head>
<body>
<div class="mermaid">
graph TD
A --> B --> C
</div>
<script src="./mermaid.js"></script>
<script>
function showFullFirstSquad(elemName) {
console.log('show ' + elemName);
}
mermaid.initialize({ startOnLoad: true, securityLevel: 'loose', logLevel: 1 });
</script>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -149,6 +149,12 @@ describe('Flowcart', () => {
{})
})
it('should render labels with numbers at the start', async () => {
await imgSnapshotTest(page, `
graph TB;subgraph "number as labels";1;end;
`,
{})
})
it('should render subgraphs', async () => {
await imgSnapshotTest(page, `
graph TB

View File

@ -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

View File

@ -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)}
;

View File

@ -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;')