MAIDR JavaScript API
    Preparing search index...
    • Creates a MAIDR figure from a Mermaid diagram that has been rendered.

      Call it after the SVG is in the page: the layers' selectors name the elements Mermaid drew. The text is parsed again with Mermaid's own parser, so pass exactly the text that was rendered.

      Unless options.language names one, the adapter's own words are written in the language MAIDR speaks to the reader, and written again when the reader changes it: the figure is converted again and handed to MAIDR, which reads it from the next time the reader enters the diagram.

      Parameters

      • mermaid: MermaidApi

        The Mermaid API: the global mermaid, or the package's default export

      • text: string

        The diagram's source text

      • svg: SVGSVGElement

        The rendered diagram

      • options: MermaidAdapterOptions = {}

        Figure options

      Returns Promise<Maidr>

      The MAIDR figure, ready for the maidr attribute

      Error when the text does not parse or the type is not supported

      const text = 'flowchart LR\n  A[Start] --> B{OK?}\n  B -->|yes| C[Ship]';
      const { svg } = await mermaid.render('flow', text);
      container.innerHTML = svg;
      const svgElement = container.querySelector('svg');
      const maidr = await maidrMermaid.createMaidrFromMermaid(mermaid, text, svgElement);
      svgElement.setAttribute('maidr', JSON.stringify(maidr));