mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-28 03: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;
|
||||
/**
|
||||
|
@@ -268,6 +268,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.
|
||||
@@ -312,6 +351,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 = {};
|
||||
@@ -357,6 +401,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{
|
||||
|
Reference in New Issue
Block a user