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.id- The SVG element IDtext- Mermaid diagram definitionsvgContainingElement(optional) - Container element
Promise<RenderResult>
parse()
Parse and validate diagram syntax.text- Diagram definitionparseOptionssuppressErrors?: boolean- Returnfalseinstead of throwing
Promise<ParseResult> or Promise<false>
initialize()
Set Mermaid configuration.getConfig()
Get the current merged configuration.setConfig()
Update the current configuration.getSiteConfig()
Get the site-level configuration (set viainitialize()).
updateSiteConfig()
Update the site-level configuration.reset()
Reset configuration to the last initialized state.globalReset()
Reset configuration to default values.getDiagramFromText()
Create a Diagram object from text (internal use).Properties
defaultConfig
The default Mermaid configuration object.Configuration hierarchy
Mermaid merges configuration from multiple sources:- defaultConfig - Built-in defaults
- Site config - Set via
initialize()orupdateSiteConfig() - Diagram directives - Set in diagram text
- Runtime config - Set via
setConfig()
Implementation details
Processing flow
ThemermaidAPI.render() method follows this internal flow:
- Preprocess - Extract directives and configuration from diagram text
- Configure - Merge configs and apply directives
- Parse - Create Diagram object from text
- Style - Generate CSS styles (theme + user styles)
- Render - Execute diagram-specific renderer
- Sanitize - Clean SVG based on security level
- Return - Provide SVG string and bind functions
Security levels
ThesecurityLevel 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:Migration guide
From mermaidAPI to mermaid
Before:- Automatic execution queueing
- Better error handling
- Future-proof (not deprecated)
When to use mermaidAPI
The only valid use cases are:- Contributing to Mermaid - Working on internal implementation
- Accessing internal utilities - When no public API exists (consider requesting one)
See also
mermaid
Recommended high-level API
Configuration
Configuration options reference