diff --git a/README.md b/README.md index fa0dd312c..06e367794 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ would render this lovely chart: ![Example 1](http://www.sveido.com/mermaid/img/ex1.png) - +A simple page with a live example can be seen [here](http://www.sveido.com/mermaid/simpleExample.html). You can also look at mermaid in action using [jsbin](http://jsbin.com/faxunexeku/1/edit?html,output). #Installation Either use the bower package manager as per below: @@ -251,5 +251,27 @@ click nodeId callback * nodeId is the id of the node * callback is the name of a javascript function defined on the page displaying the graph, the function will be called with the nodeId as parameter. +## Usage of the parser as a seperate module + +### Setup +``` +var graph = require('./graphDb'); +var flow = require('./parser/flow'); +flow.parser.yy = graph; +``` + +### Parsing + +``` +flow.parser.parse(text); +``` + +### Data extraction +``` +graph.getDirection(); +graph.getVertices(); +graph.getEdges(); +``` + # Credits Many thanks to the [d3](http://d3js.org/) and [dagre-d3](https://github.com/cpettitt/dagre-d3) projects for providing the graphical layout and drawing libraries! diff --git a/src/main.js b/src/main.js index 01c52a990..66f0d2afe 100644 --- a/src/main.js +++ b/src/main.js @@ -3,7 +3,6 @@ var flow = require('./parser/flow'); var utils = require('./utils'); var seq = require('./sequenceRenderer'); var he = require('he'); -//var dagreD3 = require('dagre-d3'); /** * Function that adds the vertices found in the graph definition to the graph to be rendered. @@ -278,7 +277,6 @@ var init = function () { cnt++; var txt = element.innerHTML; - txt = txt.replace(/>/g,'>'); txt = txt.replace(/|more text with space|C;'); @@ -173,7 +181,15 @@ describe('when parsing ',function(){ expect(vert['C'].type).toBe('round'); expect(vert['C'].text).toBe('Chimpansen hoppar åäö
- ÅÄÖ'); }); + it('should handle text in vertices with CAPS',function(){ + var res = flow.parser.parse('graph TD;A-->C(some CAPS);'); + var vert = flow.parser.yy.getVertices(); + var edges = flow.parser.yy.getEdges(); + + expect(vert['C'].type).toBe('round'); + expect(vert['C'].text).toBe('some CAPS'); + }); it('should handle a single node',function(){ // Silly but syntactically correct var res = flow.parser.parse('graph TD;A;');