Skip to content

Commit

Permalink
Added support for entity codes for sequence diagrams so that it for i…
Browse files Browse the repository at this point in the history
…nstance is possible to represent a " with #quot; and a heart with #9829;. This as referenced in issue #74 and issue #193.
  • Loading branch information
knsv committed Oct 4, 2015
1 parent a2b6bc5 commit c5d41c5
Show file tree
Hide file tree
Showing 12 changed files with 373 additions and 88 deletions.
85 changes: 60 additions & 25 deletions dist/mermaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -37504,6 +37504,7 @@ var init = function () {
mermaidAPI.initialize({gantt:mermaid.ganttConfig});
}

var txt;
var insertSvg = function(svgCode, bindFunctions){
element.innerHTML = svgCode;
if(typeof callback !== 'undefined'){
Expand All @@ -37525,35 +37526,20 @@ var init = function () {
var id = 'mermaidChart' + nextId++;

var he = _dereq_('he');
var txt = element.innerHTML;
txt = txt.replace(/>/g,'>');
txt = txt.replace(/</g,'&lt;');
txt = he.decode(txt).trim();
txt = exports.encodeEntities(txt);
if( utils.detectType(txt) === 'sequenceDiagram'){
txt = he.decode(txt).trim();
}
mermaidAPI.render(id,txt,insertSvg, element);
}
// Fetch the graph definition including tags
txt = element.innerHTML;

};
//console.warn('delivererd from the browser: ');
//console.warn(txt);

exports.encodeEntities = function(text){
var txt = text;

txt = txt.replace(/#\w*;?/g,function(s,t,u){
var innerTxt = s.substring(1,s.length-1);

var isInt = /^\+?\d+$/.test(innerTxt);
if(isInt){
return '&#'+innerTxt+';';
}else{
return '&'+innerTxt+';';
}
// transforms the html to pure text
txt = he.decode(txt).trim();
//console.warn('he decode: ');
//console.warn(txt);

});
mermaidAPI.render(id,txt,insertSvg, element);
}

return txt;
};

exports.init = init;
Expand Down Expand Up @@ -38068,6 +38054,45 @@ exports.version = function(){
return _dereq_('../package.json').version;
};

exports.encodeEntities = function(text){
var txt = text;

txt = txt.replace(/#\w*;?/g,function(s,t,u){
var innerTxt = s.substring(1,s.length-1);

var isInt = /^\+?\d+$/.test(innerTxt);
if(isInt){
return 'fl°°'+innerTxt+'¶ß';
}else{
return 'fl°'+innerTxt+'¶ß';
}

});

//txt = txt.replace(/fa:fa[\w\-]+/g,function(s,t,u){
// return 'fa:¢';
//});

return txt;
};

exports.decodeEntities = function(text){
var txt = text;

txt = txt.replace(/\fl\°\°/g,function(s,t,u){
return '&#';
});
txt = txt.replace(/\fl\°/g,function(s,t,u){
return '&';
});
txt = txt.replace(/¶ß/g,function(s,t,u){
return ';';
});



return txt;
};
/**
* ##render
* Function that renders an svg with a graph from a chart definition. Usage example below.
Expand Down Expand Up @@ -38112,6 +38137,11 @@ var render = function(id, txt, cb, container){
.append('g');
}


txt = exports.encodeEntities(txt);
//console.warn('mermaid encode: ');
//console.warn(txt);

var element = d3.select('#d'+id).node();
var graphType = utils.detectType(txt);
var classes = {};
Expand Down Expand Up @@ -38157,6 +38187,11 @@ var render = function(id, txt, cb, container){
// Fix for when the base tag is used
var svgCode = d3.select('#d'+id).node().innerHTML.replace(/url\(#arrowhead/g,'url('+ window.location.protocol+'//'+location.host+location.pathname +'#arrowhead','g');

svgCode = exports.decodeEntities(svgCode);
//console.warn('mermaid decode: ');
//console.warn(svgCode);
//var he = require('he');
//svgCode = he.decode(svgCode);
if(typeof cb !== 'undefined'){
cb(svgCode,graph.bindFunctions);
}else{
Expand Down
2 changes: 1 addition & 1 deletion dist/mermaid.min.js

Large diffs are not rendered by default.

85 changes: 60 additions & 25 deletions dist/mermaid.slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -28288,6 +28288,7 @@ var init = function () {
mermaidAPI.initialize({gantt:mermaid.ganttConfig});
}

var txt;
var insertSvg = function(svgCode, bindFunctions){
element.innerHTML = svgCode;
if(typeof callback !== 'undefined'){
Expand All @@ -28309,35 +28310,20 @@ var init = function () {
var id = 'mermaidChart' + nextId++;

var he = _dereq_('he');
var txt = element.innerHTML;
txt = txt.replace(/>/g,'&gt;');
txt = txt.replace(/</g,'&lt;');
txt = he.decode(txt).trim();
txt = exports.encodeEntities(txt);
if( utils.detectType(txt) === 'sequenceDiagram'){
txt = he.decode(txt).trim();
}
mermaidAPI.render(id,txt,insertSvg, element);
}
// Fetch the graph definition including tags
txt = element.innerHTML;

};
//console.warn('delivererd from the browser: ');
//console.warn(txt);

exports.encodeEntities = function(text){
var txt = text;

txt = txt.replace(/#\w*;?/g,function(s,t,u){
var innerTxt = s.substring(1,s.length-1);

var isInt = /^\+?\d+$/.test(innerTxt);
if(isInt){
return '&#'+innerTxt+';';
}else{
return '&'+innerTxt+';';
}
// transforms the html to pure text
txt = he.decode(txt).trim();
//console.warn('he decode: ');
//console.warn(txt);

});
mermaidAPI.render(id,txt,insertSvg, element);
}

return txt;
};

exports.init = init;
Expand Down Expand Up @@ -28852,6 +28838,45 @@ exports.version = function(){
return _dereq_('../package.json').version;
};

exports.encodeEntities = function(text){
var txt = text;

txt = txt.replace(/#\w*;?/g,function(s,t,u){
var innerTxt = s.substring(1,s.length-1);

var isInt = /^\+?\d+$/.test(innerTxt);
if(isInt){
return 'fl°°'+innerTxt+'¶ß';
}else{
return 'fl°'+innerTxt+'¶ß';
}

});

//txt = txt.replace(/fa:fa[\w\-]+/g,function(s,t,u){
// return 'fa:¢';
//});

return txt;
};

exports.decodeEntities = function(text){
var txt = text;

txt = txt.replace(/\fl\°\°/g,function(s,t,u){
return '&#';
});
txt = txt.replace(/\fl\°/g,function(s,t,u){
return '&';
});
txt = txt.replace(/¶ß/g,function(s,t,u){
return ';';
});



return txt;
};
/**
* ##render
* Function that renders an svg with a graph from a chart definition. Usage example below.
Expand Down Expand Up @@ -28896,6 +28921,11 @@ var render = function(id, txt, cb, container){
.append('g');
}


txt = exports.encodeEntities(txt);
//console.warn('mermaid encode: ');
//console.warn(txt);

var element = d3.select('#d'+id).node();
var graphType = utils.detectType(txt);
var classes = {};
Expand Down Expand Up @@ -28941,6 +28971,11 @@ var render = function(id, txt, cb, container){
// Fix for when the base tag is used
var svgCode = d3.select('#d'+id).node().innerHTML.replace(/url\(#arrowhead/g,'url('+ window.location.protocol+'//'+location.host+location.pathname +'#arrowhead','g');

svgCode = exports.decodeEntities(svgCode);
//console.warn('mermaid decode: ');
//console.warn(svgCode);
//var he = require('he');
//svgCode = he.decode(svgCode);
if(typeof cb !== 'undefined'){
cb(svgCode,graph.bindFunctions);
}else{
Expand Down
2 changes: 1 addition & 1 deletion dist/mermaid.slim.min.js

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions dist/mermaidAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -37341,6 +37341,45 @@ exports.version = function(){
return require('../package.json').version;
};

exports.encodeEntities = function(text){
var txt = text;

txt = txt.replace(/#\w*;?/g,function(s,t,u){
var innerTxt = s.substring(1,s.length-1);

var isInt = /^\+?\d+$/.test(innerTxt);
if(isInt){
return 'fl°°'+innerTxt+'¶ß';
}else{
return 'fl°'+innerTxt+'¶ß';
}

});

//txt = txt.replace(/fa:fa[\w\-]+/g,function(s,t,u){
// return 'fa:¢';
//});

return txt;
};

exports.decodeEntities = function(text){
var txt = text;

txt = txt.replace(/\fl\°\°/g,function(s,t,u){
return '&#';
});
txt = txt.replace(/\fl\°/g,function(s,t,u){
return '&';
});
txt = txt.replace(/¶ß/g,function(s,t,u){
return ';';
});



return txt;
};
/**
* ##render
* Function that renders an svg with a graph from a chart definition. Usage example below.
Expand Down Expand Up @@ -37385,6 +37424,11 @@ var render = function(id, txt, cb, container){
.append('g');
}


txt = exports.encodeEntities(txt);
//console.warn('mermaid encode: ');
//console.warn(txt);

var element = d3.select('#d'+id).node();
var graphType = utils.detectType(txt);
var classes = {};
Expand Down Expand Up @@ -37430,6 +37474,11 @@ var render = function(id, txt, cb, container){
// Fix for when the base tag is used
var svgCode = d3.select('#d'+id).node().innerHTML.replace(/url\(#arrowhead/g,'url('+ window.location.protocol+'//'+location.host+location.pathname +'#arrowhead','g');

svgCode = exports.decodeEntities(svgCode);
//console.warn('mermaid decode: ');
//console.warn(svgCode);
//var he = require('he');
//svgCode = he.decode(svgCode);
if(typeof cb !== 'undefined'){
cb(svgCode,graph.bindFunctions);
}else{
Expand Down
51 changes: 50 additions & 1 deletion dist/mermaidAPI.slim.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mermaidAPI.slim.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit c5d41c5

Please sign in to comment.