RenderResult interface represents the output of the Mermaid render function. It contains the SVG code for the rendered diagram along with optional bind functions for attaching event listeners.
Properties
string
required
The SVG code for the rendered graph. This is a complete SVG element as a string that can be inserted into the DOM.
string
required
The type of diagram that was rendered (e.g., ‘flowchart’, ‘sequence’, ‘gantt’, ‘class’, etc.).
(element: Element) => void
Optional function to be called after the SVG has been inserted into the DOM. This is necessary for adding event listeners to the elements in the SVG.This function should be called with the DOM element that contains the rendered SVG to properly attach interactive functionality.
Example usage
Basic rendering
Rendering with bind functions
Using with async/await
Destructuring the result
TypeScript definition
Notes
- The
svgproperty contains a complete SVG element as a string, ready to be inserted into the DOM - The
diagramTypecan be used to identify which type of diagram was rendered, useful for conditional logic or analytics - The
bindFunctionsproperty is optional and may not be present for all diagram types - Always call
bindFunctionsafter inserting the SVG into the DOM to ensure interactive features work correctly - Use the optional chaining operator (
?.) when callingbindFunctionsto safely handle cases where it might be undefined