var he = require('he'); var mermaidAPI = require('./mermaidAPI'); var nextId = 0; /** * Function that goes through the document to find the chart definitions in there and render them. * * The function tags the processed attributes with the attribute data-processed and ignores found elements with the * attribute already set. This way the init function can be triggered several times. * * Optionally, `init` can accept in the second argument one of the following: * - a DOM Node * - an array of DOM nodes (as would come from a jQuery selector) * - a W3C selector, a la `.mermaid` * * ``` * graph LR; * a(Find elements)-->b{Processed}; * b-->|Yes|c(Leave element); * c-->|No |d(Transform); * ``` */ /** * Renders the mermaid diagrams * @* param nodes- a css selector or an array of nodes */ var init = function () { var nodes; if(arguments.length === 2){ // sequence config was passed as #1 if(typeof arguments[0] !== 'undefined'){ mermaid.sequenceConfig = arguments[0]; } nodes = arguments[1]; } else{ nodes = arguments[0]; } nodes = nodes === undefined ? document.querySelectorAll('.mermaid') : typeof nodes === "string" ? document.querySelectorAll(nodes) : nodes instanceof Node ? [nodes] // Last case - sequence config was passed pick next : nodes; var i; console.log('Found ',nodes.length,' nodes'); console.log('Hooo hooo'); if(typeof mermaid_config !== 'undefined'){ mermaidAPI.initialize(mermaid_config); } var insertSvg = function(svgCode){ element.innerHTML = svgCode; }; for (i = 0; i < nodes.length; i++) { var element = nodes[i]; // Check if previously processed if(!element.getAttribute("data-processed")) { element.setAttribute("data-processed", true); } else { continue; } var id = 'mermaidChart' + nextId++; var txt = element.innerHTML; txt = txt.replace(/>/g,'>'); txt = txt.replace(/