Mermaid Live Editor

repository·develop·Indexed 24 days ago

https://github.com/mermaid-js/mermaid-live-editor

A web-based tool for editing, previewing, and sharing Mermaid diagrams such as flowcharts, sequence diagrams, and gantt charts in real time. The editor supports exporting diagrams as SVGs, generating shareable links, and provides features for history management, automatic saving, and external content loading via GitHub Gists or file URLs. It can be deployed using Docker or Docker Compose.

Tokens
1.9K
Snippets
2
Records
23
Agent score
92%

What's inside mermaid-live-editor

  1. Run Mermaid Live Editor via Docker

    develop

    You can run the pre-built Mermaid Live Editor image using Docker. Note that the published image uses default environment variables that cannot be overridden at runtime; you must build your own image if you need custom configurations.

    docker run --platform linux/amd64 --publish 8000:8080 ghcr.io/mermaid-js/mermaid-live-editor
  2. Run Mermaid Live Editor using Docker Compose

    develop

    You can run the Mermaid Live Editor locally using Docker Compose. The configuration builds the mermaid-dev target and maps the source code for live development.

    Default Port Mappings:

    • 3000: The main application port.
    • 24678: Internal service port.
    version: '3.7'
    services:
      mermaid:
        build:
          context: .
          target: mermaid-dev
        volumes:
          - ./src:/app/src
        ports:
          - 3000:3000
          - 24678:24678
  3. Configure the State object

    develop

    The State interface defines the configuration and current status of the Mermaid Live Editor session. It controls the diagram code, rendering options, and view settings.

    Key properties include:

    • code: The raw text input.
    • mermaid: The processed Mermaid syntax.
    • updateDiagram: Boolean to trigger diagram updates.
    • rough: Enables/disables rough diagram rendering.
    • panZoom: Enables/disables pan and zoom functionality.
    • grid: Enables/disables the background grid.
    • editorMode: Sets the editor to either 'code' or 'config' mode.
    • pan: An object containing { x: number, y: number } for viewport positioning.
    • zoom: A number representing the current zoom level.
    • loader: Configuration for loading external content via LoaderConfig.
  4. Configure content loading with LoaderConfig

    develop

    The LoaderConfig type allows the editor to fetch diagram data from external sources. It supports two types of loaders:

    1. gist: Loads content from a GitHub Gist.
      • Requires config.url (the Gist URL).
    2. files: Loads content from specific file URLs.
      • Requires config.codeURL (the URL of the diagram code).
      • Optionally accepts config.configURL (the URL of the Mermaid configuration).
  5. Add manual or auto history entries

    develop

    You can manually save the current state to history or rely on the automatic saving mechanism.

    • addManualEntry(state: State): Saves the provided State to the manual history store. Returns true if the entry was added, or false if it was a duplicate of the most recent entry.
    • addAutoEntry(state: State): Saves the provided State to the auto history store (limited to 30 entries). Returns true if added, false if it duplicated the most recent entry.