Skip to content

Commit 9c31ac8

Browse files
committed
Fix for br tags within nodes for new line
1 parent 2317ea5 commit 9c31ac8

11 files changed

+934
-179
lines changed

dist/mermaid.full.js

+399-55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mermaid.full.min.js

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mermaid.slim.js

+399-55
Large diffs are not rendered by default.

dist/mermaid.slim.min.js

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"gulp-jison": "~1.0.0",
2424
"gulp-rename": "~1.2.0",
2525
"gulp-uglify": "~1.0.1",
26+
"he": "^0.5.0",
2627
"jasmine": "~2.0.1",
2728
"jison": "~0.4.15",
2829
"karma": "~0.12.20",

src/main.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ var graph = require('./graphDb');
22
var flow = require('./parser/flow');
33
var utils = require('./utils');
44
var seq = require('./sequenceRenderer');
5+
var he = require('he');
6+
57
/**
68
* Function that adds the vertices found in the graph definition to the graph to be rendered.
79
* @param vert Object containing the vertices.
@@ -57,6 +59,7 @@ var addVertices = function (vert, g) {
5759

5860
// Create the node in the graph based on defined form
5961
if (vertice.type === 'round') {
62+
console.log(verticeText);
6063
g.setNode(vertice.id, {labelType: "html",label: verticeText, rx: 5, ry: 5, style: style, id:vertice.id});
6164
} else {
6265
if (vertice.type === 'diamond') {
@@ -226,18 +229,21 @@ var init = function () {
226229
id = 'mermaidChart' + cnt;
227230
cnt++;
228231

229-
var chartText = element.textContent.trim();
232+
var txt = element.innerHTML;
233+
txt = txt.replace(/>/g,'>');
234+
txt = txt.replace(/</g,'&lt;');
235+
txt = he.decode(txt).trim();
230236

231237
element.innerHTML = '<svg id="' + id + '" width="100%">' +
232238
'<g />' +
233239
'</svg>';
234240

235-
if(utils.detectType(chartText) === 'graph'){
236-
draw(chartText, id);
241+
if(utils.detectType(txt) === 'graph'){
242+
draw(txt, id);
237243
graph.bindFunctions();
238244
}
239245
else{
240-
seq.draw(chartText,id);
246+
seq.draw(txt,id);
241247
}
242248

243249
}
@@ -253,7 +259,7 @@ exports.version = function(){
253259
}
254260

255261
var equals = function (val, variable){
256-
if(typeof variable !== 'undefined'){
262+
if(typeof variable === 'undefined'){
257263
return false;
258264
}
259265
else{

src/parser/flow.jison

+35-14
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"]" return 'SQE';
4141
"{" return 'DIAMOND_START'
4242
"}" return 'DIAMOND_STOP'
43+
"\"" return 'QUOTE';
4344
\s return 'SPACE';
4445
\n return 'NEWLINE';
4546

@@ -97,6 +98,10 @@ vertex: alphaNum SQS text SQE
9798
{$$ = $1;yy.addVertex($1,$3,'round');}
9899
| alphaNum DIAMOND_START text DIAMOND_STOP
99100
{$$ = $1;yy.addVertex($1,$3,'diamond');}
101+
| alphaNum TAGEND text SQE
102+
{$$ = $1;yy.addVertex($1,$3,'odd');}
103+
| alphaNum TAGSTART text TAGEND
104+
{$$ = $1;yy.addVertex($1,$3,'diamond');}
100105
| alphaNum
101106
{$$ = $1;yy.addVertex($1);}
102107
;
@@ -132,10 +137,7 @@ alphaNumToken
132137
{$$ = $1;}
133138
| DOT
134139
{$$ = $1;}
135-
| TAGSTART
136-
{$$ = $1;}
137-
| TAGEND
138-
{$$ = $1;}
140+
139141
| BRKT
140142
{$$ = '<br>';}
141143
;
@@ -161,16 +163,6 @@ arrowText:
161163
{$$ = $2;}
162164
;
163165

164-
// Characters and spaces
165-
//text: alphaNum SPACE text
166-
// {$$ = $1 + ' ' +$3;}
167-
// | alphaNum spaceList MINUS spaceList text
168-
// {$$ = $1 + ' - ' +$5;}
169-
// | alphaNum spaceList TAGSTART DIR TAGEND spaceList text
170-
// {$$ = $1 + ' - ' +$5;}
171-
// | alphaNum
172-
// {$$ = $1;}
173-
// ;
174166
text: textToken
175167
{$$=$1;}
176168
| text textToken
@@ -208,6 +200,35 @@ textToken: ALPHA
208200
| MINUS
209201
{$$ = $1;}
210202
;
203+
textNoTags: textNoTagsToken
204+
{$$=$1;}
205+
| textNoTags textNoTagsToken
206+
{$$=$1+''+$2;}
207+
;
208+
209+
textNoTagsToken: ALPHA
210+
{$$=$1;}
211+
| NUM
212+
{$$=$1;}
213+
| COLON
214+
{$$ = $1;}
215+
| COMMA
216+
{$$ = $1;}
217+
| PLUS
218+
{$$ = $1;}
219+
| EQUALS
220+
{$$ = $1;}
221+
| MULT
222+
{$$ = $1;}
223+
| DOT
224+
{$$ = $1;}
225+
| BRKT
226+
{$$ = '<br>';}
227+
| SPACE
228+
{$$ = $1;}
229+
| MINUS
230+
{$$ = $1;}
231+
;
211232

212233
classDefStatement:CLASSDEF SPACE alphaNum SPACE stylesOpt
213234
{$$ = $1;yy.addClass($3,$5);}

src/parser/flow.js

+47-42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/parser/flow.spec.js

+32
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,40 @@ describe('when parsing ',function(){
224224
var vert = flow.parser.yy.getVertices();
225225
var edges = flow.parser.yy.getEdges();
226226

227+
expect(edges.length).toBe(0);
228+
expect(vert['a'].type).toBe('odd');
229+
});
230+
it('should handle a single diamond node',function(){
231+
// Silly but syntactically correct
232+
var res = flow.parser.parse('graph TD;a<A>;');
233+
234+
var vert = flow.parser.yy.getVertices();
235+
var edges = flow.parser.yy.getEdges();
236+
237+
expect(edges.length).toBe(0);
238+
expect(vert['a'].type).toBe('diamond');
239+
});
240+
it('should handle a single diamond node with html in it',function(){
241+
// Silly but syntactically correct
242+
var res = flow.parser.parse('graph TD;a<A <br> end>;');
243+
244+
var vert = flow.parser.yy.getVertices();
245+
var edges = flow.parser.yy.getEdges();
246+
227247
expect(edges.length).toBe(0);
228248
expect(vert['a'].type).toBe('diamond');
249+
expect(vert['a'].text).toBe('A <br> end');
250+
});
251+
it('should handle a single diamond node with html in it',function(){
252+
// Silly but syntactically correct
253+
var res = flow.parser.parse('graph TD;a(A <br> end);');
254+
255+
var vert = flow.parser.yy.getVertices();
256+
var edges = flow.parser.yy.getEdges();
257+
258+
expect(edges.length).toBe(0);
259+
expect(vert['a'].type).toBe('round');
260+
expect(vert['a'].text).toBe('A <br> end');
229261
});
230262
it('should handle a single node with alphanumerics starting on a char',function(){
231263
// Silly but syntactically correct

src/sequenceRenderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports.draw = function (text, id) {
2222
for(i=0;i<actorKeys.length;i++){
2323
var key = actorKeys[i];
2424

25-
console.log('Doing key: '+key)
25+
//console.log('Doing key: '+key)
2626

2727
var startMargin = 50;
2828
var margin = 50;

test/web.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<head>
44

55
<script src="../dist/mermaid.full.js"></script>
6-
<scrpt>
6+
<script>
77
var mermaid_config = {
88
startOnLoad:true
99
}
10-
</scrpt>
10+
</script>
1111
<script>
1212
function apa(){
1313
console.log('CLICKED');
@@ -22,7 +22,7 @@
2222
chimp:Chimpansenhoppar
2323
</div>
2424
<div class="mermaid">
25-
graph TB;A(Astrid # a)-->B[Irene];
25+
graph TB;A(Astrid <br> b)-->B[Irene];
2626
A-->C[Christer];
2727
B-->D[Micke];
2828
B-->E[Maria];

0 commit comments

Comments
 (0)