Skip to main content
Validates Mermaid diagram syntax without rendering. This method is useful for checking if a diagram definition is valid before attempting to render it.

Signature

Parameters

string
required
The Mermaid diagram definition to validate.
ParseOptions
Options for parsing behavior.

Return value

object | false
Returns a ParseResult object if the diagram is valid. If suppressErrors is true and the diagram is invalid, returns false instead of throwing.

Throws

  • Throws an error if the diagram is invalid and suppressErrors is false or not set
  • Error includes details about what is invalid in the diagram

Examples

Valid diagram

Invalid diagram with error suppression

Invalid diagram without error suppression

Validating user input

Detecting diagram type

Form validation

Extracting configuration

Batch validation

Usage notes

  • Parse operations are queued and execute serially, similar to render()
  • Does not produce any visual output or modify the DOM
  • Lighter weight than render() when you only need validation
  • Respects configuration from initialize() for diagram parsing
  • The parseError callback (if set) is called when errors occur, unless suppressErrors is true

Queue behavior

Like render(), parse operations are enqueued: