Adding experimental new grammars

This commit is contained in:
knsv
2014-12-04 17:58:05 +01:00
parent 2a0a2a2269
commit 4c564ebe9e
10 changed files with 1660 additions and 132 deletions

View File

@@ -1,5 +1,6 @@
var graph = require('./graphDb');
var flow = require('./parser/flow');
var dot = require('./parser/dot');
var utils = require('./utils');
var seq = require('./sequenceRenderer');
var he = require('he');
@@ -141,12 +142,19 @@ exports.addEdges = function (edges, g) {
* @param text
* @param id
*/
var draw = function (text, id) {
var draw = function (text, id,isDot) {
var parser;
graph.clear();
flow.parser.yy = graph;
if(isDot){
parser = dot.parser;
}else{
parser = flow.parser;
}
parser.yy = graph;
// Parse the graph definition
flow.parser.parse(text);
parser.parse(text);
// Fetch the default direction, use TD if none was found
var dir;
@@ -291,12 +299,19 @@ var init = function () {
'<g />' +
'</svg>';
if(utils.detectType(txt) === 'graph'){
draw(txt, id);
graph.bindFunctions();
}
else{
seq.draw(txt,id);
var graphType = utils.detectType(txt);
switch(graphType){
case 'graph':
draw(txt, id,false);
graph.bindFunctions();
break;
case 'dotGraph':
draw(txt, id,true);
break;
case 'sequenceDiagram':
seq.draw(txt,id);
break;
}
}
@@ -341,6 +356,7 @@ if(typeof document !== 'undefined'){
}
global.mermaid = {
init:function(){
init();