mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-13 20:39:38 +02:00
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:
@@ -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,'<');
|
||||
// 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;
|
||||
/**
|
||||
|
Reference in New Issue
Block a user