Search code examples
javascripthtmlmermaid

How to embed an image in a node with "mermaid.js"


Is there any way to embed a picture with mermaid.js in a flow diagram graph node? I tried:

<div class="mermaid">
  graph LR
  A(<img src="pic.svg"></img>) --> B
</div>

Solution

  • Here is the API example from this thread

    var mermaidAPI = mermaid.mermaidAPI;
    
    mermaidAPI.initialize({
      startOnLoad:false
    });
    
    var element = document.getElementById("app");
    var insertSvg = function(svgCode, bindFunctions) {
      element.innerHTML = svgCode;
    };
    var graphDefinition = `graph LR; Systemstart-->SomeIcon(<img src='https://iconscout.com/ms-icon-310x310.png' width='40' height='40' />)`;
    var graph = mermaidAPI.render("mermaid", graphDefinition, insertSvg);
    <script src="https://unpkg.com/mermaid@8.0.0-rc.8/dist/mermaid.min.js"></script>
    
    <div id="app"></div>