mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-22 16:59:48 +02:00
initial setup for editor page to generate graph through textarea input
This commit is contained in:
47
src/editor.js
Normal file
47
src/editor.js
Normal file
@@ -0,0 +1,47 @@
|
||||
function decodeHTMLEntities (str) {
|
||||
if(str && typeof str === 'string') {
|
||||
// strip script/html tags
|
||||
element = document.querySelector('.editor');
|
||||
|
||||
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;
|
||||
mermaid.init();
|
||||
document.querySelector('.editor').value = txt;
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
mermaidEditor.init();
|
||||
|
||||
}, false);
|
||||
|
||||
exports = mermaidEditor;
|
Reference in New Issue
Block a user