Skip to main content
Finds and renders all Mermaid diagrams in the document. This method processes elements matching a selector (default: .mermaid), converting their text content into SVG diagrams.

Signature

Parameters

RunOptions
Optional configuration for the run operation.

Return value

Promise<void> - Resolves when all diagrams have been rendered.

Behavior

  • Processes elements sequentially, not in parallel
  • Sets data-processed="true" attribute on rendered elements
  • Skips elements that already have data-processed attribute
  • Generates unique IDs for diagrams using format mermaid-{n}
  • Decodes HTML entities and normalizes whitespace in diagram definitions
  • Replaces element’s innerHTML with rendered SVG
  • Throws first error encountered unless suppressErrors is true

Examples

Basic usage

Custom selector

Specific nodes

With callback

Error suppression

Complete example with HTML

Usage notes

  • Can be called multiple times; already-processed diagrams are skipped
  • Use initialize() before calling run() to configure Mermaid
  • Elements must be in the DOM before calling run()
  • The method processes innerHTML, so ensure content is properly escaped
  • Diagram text is dedented and trimmed before processing
If suppressErrors is false (default), the first error will stop processing and throw. Use suppressErrors: true to render all valid diagrams even if some fail.
  • initialize() - Configure Mermaid before rendering
  • render() - Render a single diagram programmatically
  • parse() - Validate diagram syntax without rendering