mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-26 02:39:41 +02:00
Initial fix for defect #162.
This commit is contained in:
@@ -421,7 +421,6 @@ exports.draw = function (text, id,isDot) {
|
||||
// Index nodes
|
||||
graph.indexNodes('sunGraph'+i);
|
||||
|
||||
var i = 0;
|
||||
for(i=0;i<subGraphs.length;i++){
|
||||
var pos = graph.getDepthFirstPos(i);
|
||||
subG = subGraphs[i];
|
||||
|
@@ -18,7 +18,8 @@ var funs = [];
|
||||
* @param style
|
||||
*/
|
||||
exports.addVertex = function (id, text, type, style) {
|
||||
|
||||
var txt;
|
||||
|
||||
if(typeof id === 'undefined'){
|
||||
return;
|
||||
}
|
||||
@@ -30,7 +31,14 @@ exports.addVertex = function (id, text, type, style) {
|
||||
vertices[id] = {id: id, styles: [], classes:[]};
|
||||
}
|
||||
if (typeof text !== 'undefined') {
|
||||
vertices[id].text = text.trim();
|
||||
txt = text.trim();
|
||||
|
||||
// strip quotes if string starts and exnds with a quote
|
||||
if(txt[0] === '"' && txt[txt.length-1] === '"'){
|
||||
txt = txt.substring(1,txt.length-1);
|
||||
}
|
||||
|
||||
vertices[id].text = txt;
|
||||
}
|
||||
if (typeof type !== 'undefined') {
|
||||
vertices[id].type = type;
|
||||
@@ -61,6 +69,11 @@ exports.addLink = function (start, end, type, linktext) {
|
||||
|
||||
if (typeof linktext !== 'undefined') {
|
||||
edge.text = linktext.trim();
|
||||
|
||||
// strip quotes if string starts and exnds with a quote
|
||||
if(edge.text[0] === '"' && edge.text[edge.text.length-1] === '"'){
|
||||
edge.text = edge.text.substring(1,edge.text.length-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof type !== 'undefined') {
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
%%
|
||||
\%\%[^\n]* /* do nothing */
|
||||
\"[^\n]*\" return TESTSTR;
|
||||
"style" return 'STYLE';
|
||||
"default" return 'DEFAULT';
|
||||
"linkStyle" return 'LINKSTYLE';
|
||||
@@ -278,6 +279,8 @@ alphaNumStatement
|
||||
;
|
||||
|
||||
link: linkStatement arrowText
|
||||
{$1.text = $2;$$ = $1;}
|
||||
| linkStatement TESTSTR SPACE
|
||||
{$1.text = $2;$$ = $1;}
|
||||
| linkStatement arrowText SPACE
|
||||
{$1.text = $2;$$ = $1;}
|
||||
@@ -344,6 +347,8 @@ text: textToken
|
||||
{$$=$1;}
|
||||
| text textToken
|
||||
{$$=$1+''+$2;}
|
||||
| TESTSTR
|
||||
{$$=$1;}
|
||||
;
|
||||
|
||||
|
||||
|
@@ -560,6 +560,12 @@ describe('when parsing ',function(){
|
||||
var edges = flow.parser.yy.getEdges();
|
||||
expect(vert['a'].text).toBe('v');
|
||||
});
|
||||
it('should handle quoted text',function(){
|
||||
var res = flow.parser.parse('graph TD;V-- "test string" -->a[v]');
|
||||
var vert = flow.parser.yy.getVertices();
|
||||
var edges = flow.parser.yy.getEdges();
|
||||
expect(edges[0].text).toBe('test string');
|
||||
});
|
||||
});
|
||||
|
||||
describe("it should handle new line type notation",function() {
|
||||
@@ -792,6 +798,15 @@ describe('when parsing ',function(){
|
||||
expect(vert['A'].text).toBe('chimpansen hoppar');
|
||||
});
|
||||
|
||||
it('should handle quoted text in vertices ',function(){
|
||||
var res = flow.parser.parse('graph TD;A["chimpansen hoppar"] --> C;');
|
||||
|
||||
var vert = flow.parser.yy.getVertices();
|
||||
var edges = flow.parser.yy.getEdges();
|
||||
|
||||
expect(vert['A'].type).toBe('square');
|
||||
expect(vert['A'].text).toBe('chimpansen hoppar');
|
||||
});
|
||||
it('should handle text in circle vertices with space',function(){
|
||||
var res = flow.parser.parse('graph TD;A((chimpansen hoppar))-->C;');
|
||||
|
||||
|
Reference in New Issue
Block a user