Skip to main content
The mermaidAPI export is deprecated for external use. Use the mermaid export instead for all application integration.
The mermaidAPI provides lower-level functions used internally by Mermaid. While accessible, it is marked as deprecated for external use and lacks the automatic queueing and error handling of the high-level mermaid API.

Import

Interface

Key differences from mermaid

The high-level mermaid.render() wraps mermaidAPI.render() with automatic queueing. Multiple calls to mermaid.render() execute serially, while mermaidAPI.render() executes immediately.

Methods

render()

Render a diagram directly without queueing.
Parameters:
  • id - The SVG element ID
  • text - Mermaid diagram definition
  • svgContainingElement (optional) - Container element
Returns: Promise<RenderResult>
Example:
Unlike mermaid.render(), this method does not queue executions. Calling it multiple times concurrently may cause race conditions.

parse()

Parse and validate diagram syntax.
Parameters:
  • text - Diagram definition
  • parseOptions
    • suppressErrors?: boolean - Return false instead of throwing
Returns: Promise<ParseResult> or Promise<false>
Example:

initialize()

Set Mermaid configuration.
Example:

getConfig()

Get the current merged configuration.
Example:

setConfig()

Update the current configuration.
Example:

getSiteConfig()

Get the site-level configuration (set via initialize()).
Example:

updateSiteConfig()

Update the site-level configuration.
Example:

reset()

Reset configuration to the last initialized state.
Example:

globalReset()

Reset configuration to default values.
Example:

getDiagramFromText()

Create a Diagram object from text (internal use).
Example:

Properties

defaultConfig

The default Mermaid configuration object.
Example:

Configuration hierarchy

Mermaid merges configuration from multiple sources:
  1. defaultConfig - Built-in defaults
  2. Site config - Set via initialize() or updateSiteConfig()
  3. Diagram directives - Set in diagram text
  4. Runtime config - Set via setConfig()

Implementation details

Processing flow

The mermaidAPI.render() method follows this internal flow:
  1. Preprocess - Extract directives and configuration from diagram text
  2. Configure - Merge configs and apply directives
  3. Parse - Create Diagram object from text
  4. Style - Generate CSS styles (theme + user styles)
  5. Render - Execute diagram-specific renderer
  6. Sanitize - Clean SVG based on security level
  7. Return - Provide SVG string and bind functions

Security levels

The securityLevel configuration affects rendering:
  • strict (default) - DOMPurify sanitization
  • loose - No sanitization
  • sandbox - Render in sandboxed iframe

Text size limits

Diagram text is limited to prevent performance issues:
Exceeding this shows an error diagram:
Override via configuration:

Migration guide

From mermaidAPI to mermaid

Before:
After:
Benefits:
  • Automatic execution queueing
  • Better error handling
  • Future-proof (not deprecated)

When to use mermaidAPI

In general, you should not use mermaidAPI directly. Use the mermaid export instead.
The only valid use cases are:
  1. Contributing to Mermaid - Working on internal implementation
  2. Accessing internal utilities - When no public API exists (consider requesting one)

See also

mermaid

Recommended high-level API

Configuration

Configuration options reference