(function (root, factory) { if (typeof define === 'function' && define.amd) { define(["converse"], factory); } else { factory(converse); } }(this, function (converse) { var _converse = null, html; converse.plugins.add("diagrams", { 'dependencies': [], 'initialize': function () { _converse = this._converse; html = converse.env.html; _converse.api.listen.on('afterMessageBodyTransformed', function(text) { renderDiagram(text); }); mermaid.initialize({}); console.debug("diagrams plugin is ready"); } }); function renderDiagram(text) { const msgId = Math.random().toString(36).substr(2,9); //console.debug("doDiagram", text, msgId); if (text.length == 0) return; if (text.startsWith("graph TD") || text.startsWith("graph TB") || text.startsWith("graph BT") || text.startsWith("graph RL") || text.startsWith("graph LR") || text.startsWith("pie") || text.startsWith("gantt") || text.startsWith("stateDiagram") || text.startsWith("classDiagram") || text.startsWith("sequenceDiagram") || text.startsWith("erDiagram")) { text.addTemplateResult(0, text.length, html([`
\n${text.replace(/
/g, '\n')}\n
`], msgId)); setTimeout(function() { const ele = document.querySelector("#mermaid-" + msgId); if (ele) { ele.innerHTML = text; window.mermaid.init(ele); } }, 500); } else if (text.startsWith("X:1")) { text.addTemplateResult(0, text.length, html`
`); setTimeout(function() { ABCJS.renderAbc("abc-" + msgId, text.replace(/
/g, '\n'), {foregroundColor: ""}); // use default color }, 1000); } } }));