Skip to main content
The RunOptions interface defines configuration options for the mermaid.run() function, which automatically finds and renders Mermaid diagrams in the DOM.

Properties

string
default:".mermaid"
The CSS query selector to use when finding elements to render. By default, it looks for elements with the mermaid class.
ArrayLike<HTMLElement>
Specific nodes to render. If this is set, querySelector will be ignored. This allows you to provide an explicit list of elements to render instead of using a selector.
(id: string) => unknown
A callback function to call after each diagram is rendered. The function receives the diagram ID as a parameter.
boolean
default:false
If true, errors will be logged to the console but not thrown. This allows the rendering process to continue even if some diagrams fail.

Example usage

Basic usage with default selector

Custom query selector

Using specific nodes

With post-render callback

With error suppression

Complete example

Rendering specific elements

Using with initialization

TypeScript definition

Notes

  • The run() function processes elements that don’t have the data-processed attribute
  • Elements are marked with data-processed="true" after rendering to prevent re-rendering
  • If both querySelector and nodes are provided, nodes takes precedence
  • The postRenderCallback is called for each successfully rendered diagram
  • When suppressErrors is true, the first error encountered will still be logged but won’t stop execution
  • Use mermaid.initialize() before mermaid.run() to set global configuration