mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-12-08 21:45:12 +01:00
Modernization of build environment, better linting, adjustment after stricter static rules, cleanup of package.json
This commit is contained in:
@@ -2,15 +2,10 @@
|
||||
* Created by knut on 14-11-18.
|
||||
*/
|
||||
describe('when parsing an info graph it',function() {
|
||||
var parseError;
|
||||
var ex;
|
||||
beforeEach(function () {
|
||||
ex = require('./parser/example').parser;
|
||||
ex.yy = require('./exampleDb');
|
||||
parseError = function(err, hash) {
|
||||
log.debug('Syntax error:' + err);
|
||||
};
|
||||
//ex.yy.parseError = parseError;
|
||||
});
|
||||
|
||||
it('should handle an info definition', function () {
|
||||
|
||||
@@ -6,6 +6,7 @@ var message = '';
|
||||
var info = false;
|
||||
|
||||
exports.setMessage = function(txt){
|
||||
log.debug('Setting message to: '+txt);
|
||||
message = txt;
|
||||
};
|
||||
|
||||
@@ -22,5 +23,5 @@ exports.getInfo = function(){
|
||||
};
|
||||
|
||||
exports.parseError = function(err,hash){
|
||||
mermaidAPI.parseError(err,hash);
|
||||
global.mermaidAPI.parseError(err,hash);
|
||||
};
|
||||
@@ -14,14 +14,13 @@ exports.draw = function (txt, id, ver) {
|
||||
var parser;
|
||||
parser = exampleParser.parser;
|
||||
parser.yy = db;
|
||||
|
||||
log.debug('Renering example diagram');
|
||||
// Parse the graph definition
|
||||
parser.parse(txt);
|
||||
|
||||
// Fetch the default direction, use TD if none was found
|
||||
var svg = d3.select('#'+id);
|
||||
|
||||
var textstring = 'mermaid!';
|
||||
var g = svg.append('g');
|
||||
|
||||
g.append('text') // text label for the x axis
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Created by knut on 14-11-03.
|
||||
*/
|
||||
var log = require('../../logger').create();
|
||||
var d3 = require('../../d3');
|
||||
var vertices = {};
|
||||
var edges = [];
|
||||
var classes = [];
|
||||
@@ -64,7 +65,7 @@ exports.addVertex = function (id, text, type, style) {
|
||||
* @param linktext
|
||||
*/
|
||||
exports.addLink = function (start, end, type, linktext) {
|
||||
//log.debug('Got edge', start, end);
|
||||
log.debug('Got edge', start, end);
|
||||
var edge = {start: start, end: end, type: undefined, text: ''};
|
||||
linktext = type.text;
|
||||
|
||||
@@ -89,8 +90,6 @@ exports.addLink = function (start, end, type, linktext) {
|
||||
* @param style
|
||||
*/
|
||||
exports.updateLink = function (pos, style) {
|
||||
var position = pos.substr(1);
|
||||
|
||||
if(pos === 'default'){
|
||||
edges.defaultStyle = style;
|
||||
}else{
|
||||
@@ -178,7 +177,7 @@ var setLink = function(id, linkStr){
|
||||
exports.getTooltip = function(id){
|
||||
return tooltips[id];
|
||||
};
|
||||
var clickEvents = [];
|
||||
|
||||
/**
|
||||
* Called by parser when a graph definition is found, stores the direction of the chart.
|
||||
* @param dir
|
||||
@@ -243,7 +242,7 @@ var setupToolTips = function(element){
|
||||
|
||||
var nodes = svg.selectAll('g.node');
|
||||
nodes
|
||||
.on('mouseover', function(d) {
|
||||
.on('mouseover', function() {
|
||||
var el = d3.select(this);
|
||||
var title = el.attr('title');
|
||||
// Dont try to draw a tooltip if no data is provided
|
||||
@@ -261,7 +260,7 @@ var setupToolTips = function(element){
|
||||
el.classed('hover',true);
|
||||
|
||||
})
|
||||
.on('mouseout', function(d) {
|
||||
.on('mouseout', function() {
|
||||
tooltipElem.transition()
|
||||
.duration(500)
|
||||
.style('opacity', 0);
|
||||
@@ -386,17 +385,17 @@ var indexNodes = function (id, pos) {
|
||||
exports.getDepthFirstPos = function (pos) {
|
||||
return posCrossRef[pos];
|
||||
};
|
||||
exports.indexNodes = function (id) {
|
||||
exports.indexNodes = function () {
|
||||
secCount = -1;
|
||||
if(subGraphs.length>0){
|
||||
indexNodes('none',subGraphs.length-1,0);
|
||||
}
|
||||
};
|
||||
|
||||
exports.getSubGraphs = function (list) {
|
||||
exports.getSubGraphs = function () {
|
||||
return subGraphs;
|
||||
};
|
||||
|
||||
exports.parseError = function(err,hash){
|
||||
mermaidAPI.parseError(err,hash);
|
||||
global.mermaidAPI.parseError(err,hash);
|
||||
};
|
||||
@@ -2,13 +2,11 @@
|
||||
* Created by knut on 14-11-18.
|
||||
*/
|
||||
describe('when parsing a gantt diagram it',function() {
|
||||
var parseError, gantt;
|
||||
var gantt;
|
||||
beforeEach(function () {
|
||||
gantt = require('./parser/gantt').parser;
|
||||
gantt.yy = require('./ganttDb');
|
||||
parseError = function(err, hash) {
|
||||
log.debug('Syntax error:' + err);
|
||||
};
|
||||
|
||||
//ex.yy.parseError = parseError;
|
||||
});
|
||||
|
||||
|
||||
@@ -237,5 +237,5 @@ exports.addTask = function(descr,data){
|
||||
};
|
||||
|
||||
exports.parseError = function(err,hash){
|
||||
mermaidAPI.parseError(err,hash);
|
||||
global.mermaidAPI.parseError(err,hash);
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* Created by knut on 14-11-18.
|
||||
*/
|
||||
var log = require('../../logger').create();
|
||||
//var log = require('../../logger').create();
|
||||
describe('when using the ganttDb',function() {
|
||||
var parseError, gantt, gDb;
|
||||
var gDb;
|
||||
var moment = require('moment');
|
||||
|
||||
beforeEach(function () {
|
||||
@@ -11,9 +11,6 @@ describe('when using the ganttDb',function() {
|
||||
|
||||
gDb = require('./ganttDb');
|
||||
gDb.clear();
|
||||
parseError = function(err, hash) {
|
||||
log.debug('Syntax error:' + err);
|
||||
};
|
||||
//ex.yy.parseError = parseError;
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ var gantt = require('./parser/gantt').parser;
|
||||
gantt.yy = require('./ganttDb');
|
||||
var d3 = require('../../d3');
|
||||
var moment = require('moment');
|
||||
var log = require('../../logger').create();
|
||||
//var log = require('../../logger').create();
|
||||
|
||||
var daysInChart;
|
||||
var conf = {
|
||||
@@ -51,7 +51,7 @@ module.exports.draw = function (text, id) {
|
||||
|
||||
|
||||
|
||||
var dateFormat = d3.time.format('%Y-%m-%d');
|
||||
//var dateFormat = d3.time.format('%Y-%m-%d');
|
||||
|
||||
var startDate = d3.min(taskArray, function (d) {
|
||||
return d.startTime;
|
||||
@@ -90,7 +90,7 @@ module.exports.draw = function (text, id) {
|
||||
|
||||
}
|
||||
|
||||
var title = svg.append('text')
|
||||
svg.append('text')
|
||||
.text(gantt.yy.getTitle())
|
||||
.attr('x', w / 2)
|
||||
.attr('y', conf.titleTopMargin)
|
||||
@@ -117,9 +117,9 @@ module.exports.draw = function (text, id) {
|
||||
}
|
||||
|
||||
|
||||
function drawRects(theArray, theGap, theTopPad, theSidePad, theBarHeight, theColorScale, w, h) {
|
||||
function drawRects(theArray, theGap, theTopPad, theSidePad, theBarHeight, theColorScale, w, h) { //eslint-disable-line no-unused-vars
|
||||
|
||||
var bigRects = svg.append('g')
|
||||
svg.append('g')
|
||||
.selectAll('rect')
|
||||
.data(theArray)
|
||||
.enter()
|
||||
@@ -128,11 +128,11 @@ module.exports.draw = function (text, id) {
|
||||
.attr('y', function (d, i) {
|
||||
return i * theGap + theTopPad - 2;
|
||||
})
|
||||
.attr('width', function (d) {
|
||||
.attr('width', function () {
|
||||
return w - theSidePad / 2;
|
||||
})
|
||||
.attr('height', theGap)
|
||||
.attr('class', function (d) {
|
||||
.attr('class', function (d) { //eslint-disable-line no-unused-vars
|
||||
for (var i = 0; i < categories.length; i++) {
|
||||
if (d.type === categories[i]) {
|
||||
return 'section section' + (i % conf.numberSectionStyles);
|
||||
@@ -148,7 +148,7 @@ module.exports.draw = function (text, id) {
|
||||
.enter();
|
||||
|
||||
|
||||
var innerRects = rectangles.append('rect')
|
||||
rectangles.append('rect')
|
||||
.attr('rx', 3)
|
||||
.attr('ry', 3)
|
||||
.attr('x', function (d) {
|
||||
@@ -198,7 +198,7 @@ module.exports.draw = function (text, id) {
|
||||
;
|
||||
|
||||
|
||||
var rectText = rectangles.append('text')
|
||||
rectangles.append('text')
|
||||
.text(function (d) {
|
||||
return d.task;
|
||||
})
|
||||
@@ -332,7 +332,7 @@ module.exports.draw = function (text, id) {
|
||||
xAxis = xAxis.ticks(d3.time.monday.range);
|
||||
}
|
||||
|
||||
var grid = svg.append('g')
|
||||
svg.append('g')
|
||||
.attr('class', 'grid')
|
||||
.attr('transform', 'translate(' + theSidePad + ', ' + (h - 50) + ')')
|
||||
.call(xAxis)
|
||||
@@ -344,7 +344,7 @@ module.exports.draw = function (text, id) {
|
||||
.attr('dy', '1em');
|
||||
}
|
||||
|
||||
function vertLabels(theGap, theTopPad, theSidePad, theBarHeight, theColorScale) {
|
||||
function vertLabels(theGap, theTopPad) {
|
||||
var numOccurances = [];
|
||||
var prevGap = 0;
|
||||
|
||||
@@ -352,7 +352,7 @@ module.exports.draw = function (text, id) {
|
||||
numOccurances[i] = [categories[i], getCount(categories[i], catsUnfiltered)];
|
||||
}
|
||||
|
||||
var axisText = svg.append('g') //without doing this, impossible to put grid lines behind text
|
||||
svg.append('g') //without doing this, impossible to put grid lines behind text
|
||||
.selectAll('text')
|
||||
.data(numOccurances)
|
||||
.enter()
|
||||
@@ -389,7 +389,7 @@ module.exports.draw = function (text, id) {
|
||||
|
||||
var today = new Date();
|
||||
|
||||
var todayLine = todayG.append('line')
|
||||
todayG.append('line')
|
||||
.attr('x1', timeScale(today) + theSidePad)
|
||||
.attr('x2', timeScale(today) + theSidePad)
|
||||
.attr('y1', conf.titleTopMargin)
|
||||
|
||||
@@ -81,7 +81,7 @@ exports.addNote = function (actor, placement, message){
|
||||
|
||||
|
||||
exports.parseError = function(err,hash){
|
||||
mermaidAPI.parseError(err,hash);
|
||||
global.mermaidAPI.parseError(err,hash);
|
||||
};
|
||||
|
||||
exports.apply = function(param){
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Created by knut on 14-11-18.
|
||||
*/
|
||||
var proxyquire = require('proxyquire');
|
||||
var log = require('../../logger').create();
|
||||
//var log = require('../../logger').create();
|
||||
|
||||
var sq = require('./parser/sequenceDiagram').parser;
|
||||
var newD3;
|
||||
@@ -20,7 +20,6 @@ var sd = proxyquire('./sequenceRenderer', { '../../d3': d3 });
|
||||
|
||||
var str;
|
||||
describe('when parsing a sequenceDiagram',function() {
|
||||
var parseError;
|
||||
beforeEach(function () {
|
||||
sq.yy = require('./sequenceDb');
|
||||
sq.yy.clear();
|
||||
@@ -335,7 +334,7 @@ describe('when parsing a sequenceDiagram',function() {
|
||||
});});
|
||||
|
||||
describe('when checking the bounds in a sequenceDiagram',function() {
|
||||
var parseError, _d3, conf;
|
||||
var conf;
|
||||
beforeEach(function () {
|
||||
sq.yy = require('./sequenceDb');
|
||||
sq.yy.clear();
|
||||
@@ -485,11 +484,19 @@ describe('when checking the bounds in a sequenceDiagram',function() {
|
||||
});
|
||||
|
||||
describe('when rendering a sequenceDiagram',function() {
|
||||
var parseError, _d3, conf;
|
||||
var conf;
|
||||
beforeEach(function () {
|
||||
sq.yy = require('./sequenceDb');
|
||||
sq.yy.clear();
|
||||
|
||||
var MockBrowser = require('mock-browser').mocks.MockBrowser;
|
||||
var mock = new MockBrowser();
|
||||
|
||||
delete global.mermaid_config;
|
||||
|
||||
// and in the run-code inside some object
|
||||
global.document = mock.getDocument();
|
||||
global.window = mock.getWindow();
|
||||
|
||||
//parseError = function(err, hash) {
|
||||
// log.debug('Syntax error:' + err);
|
||||
@@ -499,16 +506,16 @@ describe('when rendering a sequenceDiagram',function() {
|
||||
|
||||
newD3 = function() {
|
||||
var o = {
|
||||
append: function (type) {
|
||||
append: function () {
|
||||
return newD3();
|
||||
},
|
||||
attr: function (key, val) {
|
||||
attr: function () {
|
||||
return this;
|
||||
},
|
||||
style: function (key, val) {
|
||||
style: function () {
|
||||
return this;
|
||||
},
|
||||
text: function (txt) {
|
||||
text: function () {
|
||||
return this;
|
||||
},
|
||||
0:{
|
||||
@@ -682,7 +689,7 @@ describe('when rendering a sequenceDiagram',function() {
|
||||
});
|
||||
|
||||
describe('when rendering a sequenceDiagram with actor mirror activated',function() {
|
||||
var parseError, _d3, conf;
|
||||
var conf;
|
||||
beforeEach(function () {
|
||||
sq.yy = require('./sequenceDb');
|
||||
sq.yy.clear();
|
||||
@@ -694,16 +701,16 @@ describe('when rendering a sequenceDiagram with actor mirror activated',function
|
||||
|
||||
newD3 = function() {
|
||||
var o = {
|
||||
append: function (type) {
|
||||
append: function () {
|
||||
return newD3();
|
||||
},
|
||||
attr: function (key, val) {
|
||||
attr: function () {
|
||||
return this;
|
||||
},
|
||||
style: function (key, val) {
|
||||
style: function () {
|
||||
return this;
|
||||
},
|
||||
text: function (txt) {
|
||||
text: function () {
|
||||
return this;
|
||||
},
|
||||
0:{
|
||||
|
||||
@@ -37,7 +37,7 @@ exports.bounds = {
|
||||
startx:undefined,
|
||||
stopx :undefined,
|
||||
starty:undefined,
|
||||
stopy :undefined,
|
||||
stopy :undefined
|
||||
},
|
||||
verticalPos:0,
|
||||
|
||||
@@ -48,7 +48,7 @@ exports.bounds = {
|
||||
startx:undefined,
|
||||
stopx :undefined,
|
||||
starty:undefined,
|
||||
stopy :undefined,
|
||||
stopy :undefined
|
||||
};
|
||||
this.verticalPos =0;
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Created by knut on 14-12-20.
|
||||
*/
|
||||
var log = require('../../logger').create();
|
||||
//var log = require('../../logger').create();
|
||||
exports.drawRect = function(elem , rectData){
|
||||
var rectElem = elem.append('rect');
|
||||
rectElem.attr('x', rectData.x);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
function decodeHTMLEntities (str) {
|
||||
if(str && typeof str === 'string') {
|
||||
// strip script/html tags
|
||||
element = document.querySelector('.editor');
|
||||
var element = document.querySelector('.editor');
|
||||
|
||||
str = str.replace(/<script[^>]*>([\S\s]*?)<\/script>/gmi, '');
|
||||
str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, '');
|
||||
@@ -33,7 +33,7 @@ var mermaidEditor = {
|
||||
txt = decodeHTMLEntities(txt).trim();
|
||||
|
||||
document.querySelector('.mermaid').innerHTML = txt;
|
||||
mermaid.init();
|
||||
global.mermaid.init();
|
||||
document.querySelector('.editor').value = txt;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -13,12 +13,12 @@ var Logger;
|
||||
|
||||
Logger = (function() {
|
||||
function Logger(options) {
|
||||
var level, num, ref;
|
||||
var level, ref;
|
||||
|
||||
this.options = options || {};
|
||||
this.level = this.options.level || Logger.levels.default;
|
||||
ref = Logger.levels;
|
||||
for (level in ref) {
|
||||
num = ref[level];
|
||||
Logger.define(this, level);
|
||||
}
|
||||
}
|
||||
@@ -59,9 +59,9 @@ Logger = (function() {
|
||||
}
|
||||
|
||||
Logger.prototype.write = function(options) {
|
||||
if(typeof console !== 'undefined'){
|
||||
if(typeof console.log !== 'undefined'){
|
||||
return console.log(this.build_message(options));
|
||||
if(typeof console !== 'undefined'){ //eslint-disable-line no-console
|
||||
if(typeof console.log !== 'undefined'){ //eslint-disable-line no-console
|
||||
return console.log(this.build_message(options)); //eslint-disable-line no-console
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,10 +5,8 @@
|
||||
* Created by knut on 14-11-23.
|
||||
*/
|
||||
var rewire = require('rewire');
|
||||
var utils = require('./utils');
|
||||
var mermaid = require('./mermaid');
|
||||
var log = require('./logger').create();
|
||||
console.log('here');
|
||||
//var log = require('./logger').create();
|
||||
|
||||
describe('when using mermaid and ',function() {
|
||||
describe('when detecting chart type ',function() {
|
||||
@@ -79,7 +77,6 @@ describe('when using mermaid and ',function() {
|
||||
});
|
||||
|
||||
describe('when calling addEdges ',function() {
|
||||
var mermaid;
|
||||
var graph = require('./diagrams/flowchart/graphDb');
|
||||
var flow = require('./diagrams/flowchart/parser/flow');
|
||||
var flowRend = require('./diagrams/flowchart/flowRenderer');
|
||||
@@ -94,12 +91,12 @@ describe('when using mermaid and ',function() {
|
||||
mermaid = rewire('./mermaid');
|
||||
});
|
||||
it('it should handle edges with text', function () {
|
||||
var res = flow.parser.parse('graph TD;A-->|text ex|B;');
|
||||
var vert = flow.parser.yy.getVertices();
|
||||
flow.parser.parse('graph TD;A-->|text ex|B;');
|
||||
flow.parser.yy.getVertices();
|
||||
var edges = flow.parser.yy.getEdges();
|
||||
|
||||
var mockG = {
|
||||
setEdge:function(start, end,options,name){
|
||||
setEdge:function(start, end,options){
|
||||
expect(start).toBe('A');
|
||||
expect(end).toBe('B');
|
||||
expect(options.arrowhead).toBe('normal');
|
||||
@@ -111,12 +108,12 @@ describe('when using mermaid and ',function() {
|
||||
});
|
||||
|
||||
it('should handle edges without text', function () {
|
||||
var res = flow.parser.parse('graph TD;A-->B;');
|
||||
var vert = flow.parser.yy.getVertices();
|
||||
flow.parser.parse('graph TD;A-->B;');
|
||||
flow.parser.yy.getVertices();
|
||||
var edges = flow.parser.yy.getEdges();
|
||||
|
||||
var mockG = {
|
||||
setEdge:function(start, end,options,name){
|
||||
setEdge:function(start, end,options){
|
||||
expect(start).toBe('A');
|
||||
expect(end).toBe('B');
|
||||
expect(options.arrowhead).toBe('normal');
|
||||
@@ -128,12 +125,12 @@ describe('when using mermaid and ',function() {
|
||||
|
||||
|
||||
it('should handle open-ended edges', function () {
|
||||
var res = flow.parser.parse('graph TD;A---B;');
|
||||
var vert = flow.parser.yy.getVertices();
|
||||
flow.parser.parse('graph TD;A---B;');
|
||||
flow.parser.yy.getVertices();
|
||||
var edges = flow.parser.yy.getEdges();
|
||||
|
||||
var mockG = {
|
||||
setEdge:function(start, end,options,name){
|
||||
setEdge:function(start, end,options){
|
||||
expect(start).toBe('A');
|
||||
expect(end).toBe('B');
|
||||
expect(options.arrowhead).toBe('none');
|
||||
@@ -144,12 +141,12 @@ describe('when using mermaid and ',function() {
|
||||
});
|
||||
|
||||
it('should handle edges with styles defined', function () {
|
||||
var res = flow.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;');
|
||||
var vert = flow.parser.yy.getVertices();
|
||||
flow.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;');
|
||||
flow.parser.yy.getVertices();
|
||||
var edges = flow.parser.yy.getEdges();
|
||||
|
||||
var mockG = {
|
||||
setEdge:function(start, end,options,name){
|
||||
setEdge:function(start, end,options){
|
||||
expect(start).toBe('A');
|
||||
expect(end).toBe('B');
|
||||
expect(options.arrowhead).toBe('none');
|
||||
@@ -160,12 +157,12 @@ describe('when using mermaid and ',function() {
|
||||
flowRend.addEdges(edges,mockG);
|
||||
});
|
||||
it('should handle edges with text and styles defined', function () {
|
||||
var res = flow.parser.parse('graph TD;A---|the text|B; linkStyle 0 stroke:val1,stroke-width:val2;');
|
||||
var vert = flow.parser.yy.getVertices();
|
||||
flow.parser.parse('graph TD;A---|the text|B; linkStyle 0 stroke:val1,stroke-width:val2;');
|
||||
flow.parser.yy.getVertices();
|
||||
var edges = flow.parser.yy.getEdges();
|
||||
|
||||
var mockG = {
|
||||
setEdge:function(start, end,options,name){
|
||||
setEdge:function(start, end,options){
|
||||
expect(start).toBe('A');
|
||||
expect(end).toBe('B');
|
||||
expect(options.arrowhead).toBe('none');
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
* somewhere in the page or something completely different.
|
||||
*/
|
||||
var graph = require('./diagrams/flowchart/graphDb');
|
||||
|
||||
var flow = require('./diagrams/flowchart/parser/flow');
|
||||
var utils = require('./utils');
|
||||
var flowRenderer = require('./diagrams/flowchart/flowRenderer');
|
||||
var seq = require('./diagrams/sequenceDiagram/sequenceRenderer');
|
||||
@@ -28,7 +26,6 @@ var gantt = require('./diagrams/gantt/ganttRenderer');
|
||||
var ganttParser = require('./diagrams/gantt/parser/gantt');
|
||||
var ganttDb = require('./diagrams/gantt/ganttDb');
|
||||
var d3 = require('./d3');
|
||||
var nextId = 0;
|
||||
|
||||
/**
|
||||
* ## Configuration
|
||||
@@ -282,16 +279,16 @@ exports.version = function(){
|
||||
exports.encodeEntities = function(text){
|
||||
var txt = text;
|
||||
|
||||
txt = txt.replace(/style.*:\S*#.*;/g,function(s,t,u){
|
||||
txt = txt.replace(/style.*:\S*#.*;/g,function(s){
|
||||
var innerTxt = s.substring(0,s.length-1);
|
||||
return innerTxt;
|
||||
});
|
||||
txt = txt.replace(/classDef.*:\S*#.*;/g,function(s,t,u){
|
||||
txt = txt.replace(/classDef.*:\S*#.*;/g,function(s){
|
||||
var innerTxt = s.substring(0,s.length-1);
|
||||
return innerTxt;
|
||||
});
|
||||
|
||||
txt = txt.replace(/#\w+\;/g,function(s,t,u){
|
||||
txt = txt.replace(/#\w+\;/g,function(s){
|
||||
var innerTxt = s.substring(1,s.length-1);
|
||||
|
||||
var isInt = /^\+?\d+$/.test(innerTxt);
|
||||
@@ -309,13 +306,13 @@ exports.encodeEntities = function(text){
|
||||
exports.decodeEntities = function(text){
|
||||
var txt = text;
|
||||
|
||||
txt = txt.replace(/\fl\°\°/g,function(s,t,u){
|
||||
txt = txt.replace(/\fl\°\°/g,function(){
|
||||
return '&#';
|
||||
});
|
||||
txt = txt.replace(/\fl\°/g,function(s,t,u){
|
||||
txt = txt.replace(/\fl\°/g,function(){
|
||||
return '&';
|
||||
});
|
||||
txt = txt.replace(/¶ß/g,function(s,t,u){
|
||||
txt = txt.replace(/¶ß/g,function(){
|
||||
return ';';
|
||||
});
|
||||
|
||||
@@ -490,7 +487,7 @@ exports.getConfig = function(){
|
||||
|
||||
exports.parseError = function(err, hash) {
|
||||
if(typeof mermaid !== 'undefined') {
|
||||
mermaid.parseError(err,hash);
|
||||
global.mermaid.parseError(err,hash);
|
||||
}else{
|
||||
log.debug('Mermaid Syntax error:');
|
||||
log.debug(err);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Created by knut on 14-11-23.
|
||||
*/
|
||||
var api = require('./mermaidAPI.js');
|
||||
var log = require('./logger').create();
|
||||
//var log = require('./logger').create();
|
||||
|
||||
describe('when using mermaidAPI and ',function() {
|
||||
describe('doing initialize ',function() {
|
||||
@@ -19,8 +19,8 @@ describe('when using mermaidAPI and ',function() {
|
||||
delete global.mermaid_config;
|
||||
|
||||
// and in the run-code inside some object
|
||||
document = mock.getDocument();
|
||||
window = mock.getWindow();
|
||||
global.document = mock.getDocument();
|
||||
global.window = mock.getWindow();
|
||||
});
|
||||
|
||||
it('should copy a literal into the configuration', function () {
|
||||
@@ -63,7 +63,7 @@ describe('when using mermaidAPI and ',function() {
|
||||
});
|
||||
it('it should return true for a valid definiton',function(){
|
||||
spyOn(global.mermaidAPI,'parseError');
|
||||
var res = mermaid.parse('graph TD;A--x|text including URL space|B;');
|
||||
var res = global.mermaid.parse('graph TD;A--x|text including URL space|B;');
|
||||
|
||||
expect(res).toBe(true);
|
||||
expect(global.mermaidAPI.parseError).not.toHaveBeenCalled();
|
||||
|
||||
17
src/utils.js
17
src/utils.js
@@ -19,10 +19,9 @@ var log = Log.create();
|
||||
* ```
|
||||
*
|
||||
* @param {string} text The text defining the graph
|
||||
* @param {string} text The second text defining the graph
|
||||
* @returns {string} A graph definition key
|
||||
*/
|
||||
var detectType = function(text,a){
|
||||
var detectType = function(text){
|
||||
text = text.replace(/^\s*%%.*\n/g,'\n');
|
||||
if(text.match(/^\s*sequenceDiagram/)){
|
||||
return 'sequenceDiagram';
|
||||
@@ -43,8 +42,6 @@ var detectType = function(text,a){
|
||||
return 'gantt';
|
||||
}
|
||||
|
||||
console.warn('detecting type!');
|
||||
|
||||
return 'graph';
|
||||
};
|
||||
export {detectType};
|
||||
@@ -56,9 +53,9 @@ export {detectType};
|
||||
* @param {object} Hash table of class definitions from the graph definition
|
||||
*/
|
||||
var cloneCssStyles = function(svg, classes){
|
||||
console.warn('cloneCssStyles ----');
|
||||
var usedStyles = '';
|
||||
var sheets = document.styleSheets;
|
||||
var rule;
|
||||
for (var i = 0; i < sheets.length; i++) {
|
||||
// Avoid multiple inclusion on pages with multiple graphs
|
||||
if (sheets[i].title !== 'mermaid-svg-internal-css') {
|
||||
@@ -67,7 +64,7 @@ var cloneCssStyles = function(svg, classes){
|
||||
var rules = sheets[i].cssRules;
|
||||
if (rules !== null) {
|
||||
for (var j = 0; j < rules.length; j++) {
|
||||
var rule = rules[j];
|
||||
rule = rules[j];
|
||||
if (typeof(rule.style) !== 'undefined') {
|
||||
var elems;
|
||||
elems = svg.querySelectorAll(rule.selectorText);
|
||||
@@ -79,12 +76,8 @@ var cloneCssStyles = function(svg, classes){
|
||||
}
|
||||
}
|
||||
catch(err) {
|
||||
if(typeof console !== 'undefined'){
|
||||
if(console.warn !== 'undefined'){
|
||||
if(rule !== 'undefined'){
|
||||
console.warn('Invalid CSS selector "' + rule.selectorText + '"', err);
|
||||
}
|
||||
}
|
||||
if(rule !== 'undefined'){
|
||||
log.warn('Invalid CSS selector "' + rule.selectorText + '"', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user