Skip to content

Commit 0ed5a01

Browse files
committed
Fix fir defect #141 regarding comment characters
1 parent 22b9ee4 commit 0ed5a01

File tree

11 files changed

+625
-521
lines changed

11 files changed

+625
-521
lines changed

dist/mermaid.full.js

Lines changed: 167 additions & 172 deletions
Large diffs are not rendered by default.

dist/mermaid.full.min.js

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mermaid.slim.js

Lines changed: 167 additions & 172 deletions
Large diffs are not rendered by default.

dist/mermaid.slim.min.js

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/diagrams/flowchart/d3.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* global window */
2+
3+
var d3;
4+
5+
if (require) {
6+
try {
7+
d3 = require("d3");
8+
} catch (e) {}
9+
}
10+
11+
if (!d3) {
12+
d3 = window.d3;
13+
}
14+
15+
module.exports = d3;

src/diagrams/flowchart/flowRenderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var graph = require('./graphDb');
55
var flow = require('./parser/flow');
66
var dot = require('./parser/dot');
77
var dagreD3 = require('./dagre-d3');
8+
var d3 = require('./d3');
89
var conf = {
910
};
1011
module.exports.setConf = function(cnf){
@@ -419,8 +420,7 @@ exports.draw = function (text, id,isDot) {
419420
svg.attr("width", conf.width );
420421
}
421422
//svg.attr("viewBox", svgb.getBBox().x + ' 0 '+ g.graph().width+' '+ g.graph().height);
422-
svg.attr("viewBox", '0 0 '+ g.graph().width+' '+ g.graph().height);
423-
423+
svg.attr("viewBox", '0 0 ' + (g.graph().width+20) + ' ' + (g.graph().height+20));
424424

425425
setTimeout(function(){
426426
var i = 0;

src/diagrams/flowchart/parser/flow.jison

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
%lex
99

1010
%%
11-
\%\%[^\n]* {console.log('comment: '+yytext)}
11+
\%\%[^\n]* /* do nothing */
1212
"style" return 'STYLE';
1313
"default" return 'DEFAULT';
1414
"linkStyle" return 'LINKSTYLE';
@@ -157,11 +157,11 @@ document
157157
;
158158

159159
line
160-
: spaceListNewline statement
161-
{$$=$2;}
162-
| statement
160+
: statement
163161
{$$=$1;}
164162
| SEMI
163+
| NEWLINE
164+
| SPACE
165165
| EOF
166166
;
167167

@@ -216,21 +216,17 @@ statement
216216
{$$=[];}
217217
| clickStatement separator
218218
{$$=[];}
219-
| subgraph text separator document endStatement separator
219+
| subgraph text separator document end separator
220220
{yy.addSubGraph($4,$2);}
221-
| subgraph separator document endStatement separator
221+
| subgraph separator document end separator
222222
{yy.addSubGraph($3,undefined);}
223223
;
224224

225-
endStatement: end
226-
| SPACE endStatement
227-
;
228-
229-
separator: NEWLINE {console.log('nl sep')} | SEMI {console.log('semi sep')}| EOF {console.log('eof sep')};
225+
separator: NEWLINE | SEMI | EOF ;
230226

231227
verticeStatement:
232228
vertex link vertex
233-
{ console.log($3);yy.addLink($1,$3,$2);$$ = [$1,$3];}
229+
{ yy.addLink($1,$3,$2);$$ = [$1,$3];}
234230
| vertex
235231
{$$ = [$1];}
236232
;

src/diagrams/flowchart/parser/flow.js

Lines changed: 128 additions & 135 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/diagrams/flowchart/parser/flow.spec.js

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,98 @@ describe('when parsing ',function(){
170170
expect(edges[0].type).toBe('arrow');
171171
expect(edges[0].text).toBe('');
172172
});
173+
it('should handle comments a at the start',function(){
174+
var res = flow.parser.parse('%% Comment\ngraph TD;\n A-->B;');
173175

176+
177+
var vert = flow.parser.yy.getVertices();
178+
var edges = flow.parser.yy.getEdges();
179+
180+
expect(vert['A'].id).toBe('A');
181+
expect(vert['B'].id).toBe('B');
182+
expect(edges.length).toBe(1);
183+
expect(edges[0].start).toBe('A');
184+
expect(edges[0].end).toBe('B');
185+
expect(edges[0].type).toBe('arrow');
186+
expect(edges[0].text).toBe('');
187+
});
188+
it('should handle comments at the end',function(){
189+
var res = flow.parser.parse('graph TD;\n A-->B\n %% Comment at the find\n');
190+
191+
192+
var vert = flow.parser.yy.getVertices();
193+
var edges = flow.parser.yy.getEdges();
194+
195+
expect(vert['A'].id).toBe('A');
196+
expect(vert['B'].id).toBe('B');
197+
expect(edges.length).toBe(1);
198+
expect(edges[0].start).toBe('A');
199+
expect(edges[0].end).toBe('B');
200+
expect(edges[0].type).toBe('arrow');
201+
expect(edges[0].text).toBe('');
202+
});
203+
it('should handle comments at the end no trailing newline',function(){
204+
var res = flow.parser.parse('graph TD;\n A-->B\n%% Commento');
205+
206+
207+
var vert = flow.parser.yy.getVertices();
208+
var edges = flow.parser.yy.getEdges();
209+
210+
expect(vert['A'].id).toBe('A');
211+
expect(vert['B'].id).toBe('B');
212+
expect(edges.length).toBe(1);
213+
expect(edges[0].start).toBe('A');
214+
expect(edges[0].end).toBe('B');
215+
expect(edges[0].type).toBe('arrow');
216+
expect(edges[0].text).toBe('');
217+
});
218+
it('should handle comments at the end many trailing newlines',function(){
219+
var res = flow.parser.parse('graph TD;\n A-->B\n%% Commento\n\n\n');
220+
221+
222+
var vert = flow.parser.yy.getVertices();
223+
var edges = flow.parser.yy.getEdges();
224+
225+
expect(vert['A'].id).toBe('A');
226+
expect(vert['B'].id).toBe('B');
227+
expect(edges.length).toBe(1);
228+
expect(edges[0].start).toBe('A');
229+
expect(edges[0].end).toBe('B');
230+
expect(edges[0].type).toBe('arrow');
231+
expect(edges[0].text).toBe('');
232+
});
233+
it('should handle no trailing newlines',function(){
234+
var res = flow.parser.parse('graph TD;\n A-->B');
235+
236+
237+
var vert = flow.parser.yy.getVertices();
238+
var edges = flow.parser.yy.getEdges();
239+
240+
expect(vert['A'].id).toBe('A');
241+
expect(vert['B'].id).toBe('B');
242+
expect(edges.length).toBe(1);
243+
expect(edges[0].start).toBe('A');
244+
expect(edges[0].end).toBe('B');
245+
expect(edges[0].type).toBe('arrow');
246+
expect(edges[0].text).toBe('');
247+
});
248+
it('should handle many trailing newlines',function(){
249+
var res = flow.parser.parse('graph TD;\n A-->B\n\n');
250+
251+
252+
var vert = flow.parser.yy.getVertices();
253+
var edges = flow.parser.yy.getEdges();
254+
255+
expect(vert['A'].id).toBe('A');
256+
expect(vert['B'].id).toBe('B');
257+
expect(edges.length).toBe(1);
258+
expect(edges[0].start).toBe('A');
259+
expect(edges[0].end).toBe('B');
260+
expect(edges[0].type).toBe('arrow');
261+
expect(edges[0].text).toBe('');
262+
});
174263
it('should handle a comments with blank rows in-between',function(){
175-
var res = flow.parser.parse('graph TD;\n\n\n %% CComment\n A-->B;');
264+
var res = flow.parser.parse('graph TD;\n\n\n %% Comment\n A-->B;');
176265

177266

178267
var vert = flow.parser.yy.getVertices();
@@ -204,7 +293,7 @@ describe('when parsing ',function(){
204293
});
205294

206295
it('it should handle a trailing whitespaces after statememnts',function(){
207-
var res = flow.parser.parse('graph TD;\n\n\n %% CComment\n A-->B; \n B-->C;');
296+
var res = flow.parser.parse('graph TD;\n\n\n %% Comment\n A-->B; \n B-->C;');
208297

209298

210299
var vert = flow.parser.yy.getVertices();

src/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ var init = function (sequenceConfig, arr) {
8181
: arr instanceof Node ? [arr]
8282
: arr;
8383

84-
var arr = document.querySelectorAll('.mermaid');
84+
//arr = document.querySelectorAll('.mermaid');
8585
var i;
8686

8787
if (sequenceConfig !== 'undefined' && (typeof sequenceConfig !== 'undefined')) {
@@ -195,7 +195,7 @@ global.mermaid = {
195195
};
196196

197197
exports.contentLoaded = function(){
198-
// Check state of start config mermaid namespece
198+
// Check state of start config mermaid namespace
199199
//console.log('global.mermaid.startOnLoad',global.mermaid.startOnLoad);
200200
//console.log('mermaid_config',mermaid_config);
201201
if (typeof mermaid_config !== 'undefined') {

test/web.html

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,28 @@
2929
<link rel="stylesheet" href="../dist/mermaid.css"/>
3030
</head>
3131
<body>
32-
<div class="mermaid">
32+
<h1>Issue 141</h1>
33+
<div class="mermaid" id="i141">
34+
35+
graph LR
36+
37+
%% Example diagram
38+
A[Square Rect] -- Link text --> B((Circle))
39+
A --> C(Round Rect)
40+
B --> D{Rhombus}
41+
C --> D
42+
43+
</div>
44+
<h1>Issue 140</h1>
45+
<div class="mermaid" id="i140">
46+
graph LR
47+
A-->B
48+
B-->C
49+
C-->A
50+
D-->C
51+
52+
</div>
53+
<div class="mermaid" id="ettan">
3354
graph LR;
3455
A[Now with default style on links]--v-->B{a = '1,2'}
3556
B-->|v|C[v]
@@ -104,7 +125,7 @@ <h1>Sub graphs</h1>
104125
c1-->a2
105126

106127
</div>
107-
<div class="mermaid">graph TB
128+
<div class="mermaid" >graph TB
108129
subgraph
109130
sq[Square shape] -.-> ci((Circle shape))
110131
od>Odd shape]-. Two line<br>edge comment .-> ro

0 commit comments

Comments
 (0)