2014-12-01 20:50:58 +01:00
|
|
|
function decodeHTMLEntities (str) {
|
|
|
|
if(str && typeof str === 'string') {
|
|
|
|
// strip script/html tags
|
2015-10-17 12:46:36 +02:00
|
|
|
var element = document.querySelector('.editor');
|
2014-12-01 20:50:58 +01:00
|
|
|
|
|
|
|
str = str.replace(/<script[^>]*>([\S\s]*?)<\/script>/gmi, '');
|
|
|
|
str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, '');
|
|
|
|
element.innerHTML = str;
|
|
|
|
str = element.textContent;
|
|
|
|
element.textContent = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
var mermaidEditor = {
|
|
|
|
$ : document.querySelector,
|
|
|
|
textField : '',
|
|
|
|
submit : '',
|
|
|
|
graph : '',
|
|
|
|
|
|
|
|
init: function () {
|
|
|
|
|
|
|
|
document.querySelector('.button').addEventListener('click', function () {
|
|
|
|
mermaidEditor.update();
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
update: function () {
|
|
|
|
var txt = document.querySelector('.editor').value;
|
|
|
|
txt = txt.replace(/>/g,'>');
|
|
|
|
txt = txt.replace(/</g,'<');
|
|
|
|
txt = decodeHTMLEntities(txt).trim();
|
|
|
|
|
|
|
|
document.querySelector('.mermaid').innerHTML = txt;
|
2015-10-17 12:46:36 +02:00
|
|
|
global.mermaid.init();
|
2014-12-01 20:50:58 +01:00
|
|
|
document.querySelector('.editor').value = txt;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
|
|
|
|
mermaidEditor.init();
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
exports = mermaidEditor;
|