Added support for entity codes so that it for instance is possible to represent a " with #quot; and a heart with #9829; This differs from the regular html codes in that the leading & isreplaced with a dsh and for dec codes dropped. This as referenced in issue #219.

This commit is contained in:
knsv
2015-10-03 21:50:32 +02:00
parent cb5e88c2f1
commit a2b6bc5213
12 changed files with 129 additions and 46 deletions

View File

@@ -20,6 +20,7 @@
var mermaidAPI = require('./mermaidAPI');
var nextId = 0;
var log = require('./logger').create();
var utils = require('./utils');
module.exports.mermaidAPI = mermaidAPI;
/**
@@ -122,12 +123,33 @@ var init = function () {
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);
}
};
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;
/**