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