mermaid export is the primary API for integrating Mermaid into your application. It provides a queue-based, user-friendly interface for rendering diagrams, parsing syntax, and managing configuration.
Import
Interface
Core methods
initialize()
Configure Mermaid before rendering diagrams.Call
initialize() before using run() or render(). Configuration set here applies to all subsequent operations.config- Configuration object. See Configuration for all options.
render()
Render a diagram to SVG code programmatically.id- Unique identifier for the SVG elementtext- Mermaid diagram definitioncontainer(optional) - HTML element where the SVG will be inserted
Promise<RenderResult>
Multiple calls to
render() are automatically queued and executed serially to prevent race conditions.parse()
Validate diagram syntax and return metadata.text- Mermaid diagram definition to parseparseOptions(optional)suppressErrors?: boolean- Returnfalseinstead of throwing on error
Promise<ParseResult> or Promise<false> when suppressErrors: true
run()
Find and render all diagrams in the DOM.options(optional)
run() skips elements that have already been processed (marked with data-processed attribute). You can call it multiple times safely.Registration methods
registerExternalDiagrams()
Register custom diagram types.diagrams- Array of diagram definitionsoptions.lazyLoad- Iffalse, load immediately. Default:true
registerLayoutLoaders()
Register custom layout algorithms.registerIconPacks()
Register custom icon packs for use in diagrams.Utility methods
detectType()
Detect the diagram type from text.getRegisteredDiagramsMetadata()
Get metadata for all registered diagram types.setParseErrorHandler()
Set a global error handler for parse errors.Properties
startOnLoad
Control whether Mermaid automatically renders diagrams on page load.It’s better to use
initialize({ startOnLoad: false }) instead of setting this property directly.Deprecated methods
init()
Complete example
See also
mermaidAPI
Lower-level API (internal use)
Configuration
Configuration options reference