Added support for entity codes for sequence diagrams so that it for instance is possible to represent a " with #quot; and a heart with #9829;. This as referenced in issue #74 and issue #193.

This commit is contained in:
knsv
2015-10-04 14:05:53 +02:00
parent a2b6bc5213
commit c5d41c5a21
12 changed files with 373 additions and 88 deletions

View File

@@ -98,6 +98,7 @@ var init = function () {
mermaidAPI.initialize({gantt:mermaid.ganttConfig});
}
var txt;
var insertSvg = function(svgCode, bindFunctions){
element.innerHTML = svgCode;
if(typeof callback !== 'undefined'){
@@ -119,37 +120,22 @@ var init = function () {
var id = 'mermaidChart' + nextId++;
var he = require('he');
var txt = element.innerHTML;
txt = txt.replace(/>/g,'>');
txt = txt.replace(/</g,'&lt;');
// Fetch the graph definition including tags
txt = element.innerHTML;
//console.warn('delivererd from the browser: ');
//console.warn(txt);
// transforms the html to pure text
txt = he.decode(txt).trim();
txt = exports.encodeEntities(txt);
if( utils.detectType(txt) === 'sequenceDiagram'){
txt = he.decode(txt).trim();
}
//console.warn('he decode: ');
//console.warn(txt);
mermaidAPI.render(id,txt,insertSvg, element);
}
};
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+';';
}
});
return txt;
};
exports.init = init;
exports.parse = mermaidAPI.parse;
/**