Mermaid Preview for Visual Studio Code

repository·master·Indexed 42 days ago

https://github.com/mermaid-chart/vscode-mermaid-preview

A local-first Visual Studio Code extension for real-time previewing and editing of Mermaid.js diagrams. It provides side-by-side editing, syntax highlighting, pan and zoom capabilities, and support for exporting diagrams as SVG or PNG. The extension automatically detects Mermaid diagrams within Markdown files and supports a wide range of diagram types, including Flowchart, Sequence, Gantt, and Mindmap. Version 2.2.0 focuses on local use, while cloud-based features have moved to the separate Mermaid extension.

Tokens
7.8K
Snippets
29
Records
50
Agent score
53%

What's inside Mermaid Preview

  1. Overview of Mermaid Preview

    master

    Mermaid Preview is a Visual Studio Code extension focused on free, local diagram previewing. It provides real-time side-by-side editing, syntax highlighting, pan and zoom capabilities, and support for exporting diagrams as SVG or PNG.

    Note on Feature Split: This extension is for local use. Features such as account login, cloud sync, AI diagramming, and cloud saving have moved to the Mermaid extension.

  2. Understand the extension structure

    master

    The extension project is organized as follows:

    • package.json: The manifest file. It is used to declare the extension, define commands, and set their titles/names so they appear in the Command Palette.
    • src/mermaidChart.ts: The main implementation file. It must export an activate function, which VS Code calls when the extension is first triggered. Inside activate, you use registerCommand to bind your logic to a command name.
    • src/test/suite/: Contains test files (matching **.test.ts).
  3. Identify features available in Mermaid Preview vs the Mermaid extension

    master

    The functionality of the ecosystem is split between two extensions. Use Mermaid Preview for local development and the Mermaid extension for cloud/account-based workflows.

    Available in Mermaid Preview (Local Only)

    • Live diagram preview (with pan, zoom, and reset)
    • Export to PNG and SVG
    • Mermaid diagrams inside Markdown preview
    • Auto-detection of Mermaid blocks in Markdown, HTML, Hugo, and reStructuredText (includes an Edit Diagram link)
    • Syntax highlighting for .mmd and .mermaid files
    • Diagram templates and snippets
    • Create Diagram and Diagram help commands
    • Local sidebar home and settings (Theme, max zoom, max text size, max edges)

    Moved to the Mermaid extension (Cloud/Account Required)

    • Sync Diagram: Saving a diagram to your Mermaid account
    • Connect Diagram: Attaching a local diagram to a Mermaid project
    • Link Diagram: Inserting a Mermaid diagram ID into your code
    • Login / Logout: Account management
    • Cloud diagram browser: Browsing projects in the side panel
    • Download diagram: Pulling cloud diagrams into the editor
    • Refresh: Re-syncing the cloud diagram list
    • Smart sync & conflict detection
    • AI chat & Regenerate Diagram
  4. Run extension tests

    master

    To execute the test suite:

    1. Open the Debug viewlet (Ctrl+Shift+D or Cmd+Shift+D on Mac).
    2. Select Extension Tests from the launch configuration dropdown.
    3. Press F5 to run the tests in a new window.
    4. View results in the Debug Console.

    Test Configuration Rules:

    • The test runner automatically includes files matching the pattern **.test.ts.
    • You can organize tests by creating custom folders within the test directory.
    • Test implementations are located in src/test/suite/mermaidChart.test.ts.
    # Select 'Extension Tests' in the Debug viewlet and press F5
  5. Preview Mermaid diagrams in Markdown

    master

    The extension automatically detects Mermaid diagrams within Markdown files using the ```mermaid code block.

    • Live Preview: Mermaid diagrams are rendered directly within the VS Code Markdown preview.
    • Edit Link: You can click the 'edit diagram' link directly from within the Markdown file to open the diagram for editing.
  6. Migrate to the Mermaid extension for cloud features

    master

    As of version 2.2.0, Mermaid Preview is a local-only extension. Features requiring a Mermaid account (such as syncing, connecting, or AI-assisted generation) have been moved to the official Mermaid extension.

    To continue using cloud-based features, follow these steps:

    1. Install the Mermaid extension from the VS Code Marketplace.
    2. Sign in with your Mermaid account.
    3. Use the Mermaid extension for Sync, Connect, Link, and cloud side panel operations.
  7. Run and debug the VS Code extension

    master

    To start developing, press F5 to launch a new VS Code window (Extension Development Host) with your extension loaded. You can execute your extension's commands via the Command Palette (Ctrl+Shift+P or Cmd+Shift+P) by typing the command name defined in package.json (e.g., Hello World).

    To debug, set breakpoints in src/mermaidChart.ts. When the command is executed, the execution will pause at your breakpoints, and you can inspect variables and view output in the Debug Console.

    # Press F5 to launch the extension host
    # Press Ctrl+Shift+P then type 'Hello World' to run the command
  8. Configure Mermaid Preview Settings

    master

    The extension provides several configuration options to customize the preview experience. You can access these via the sidebar or the standard VS Code settings menu.

    Extension Settings

    KeyDescription
    mermaid.vscode.dark_themeDefines the theme used for Mermaid diagrams when VS Code is in dark mode.
    mermaid.vscode.light_themeDefines the theme used for Mermaid diagrams when VS Code is in light mode.
    mermaid.vscode.max_ZoomMaximum zoom level for diagrams, as a multiple of 100%. (e.g., 5 = 500%).
    mermaid.vscode.max_CharLengthMaximum number of characters allowed in a diagram's source.
    mermaid.vscode.max_EdgesMaximum number of edges allowed in a diagram's source.
    preview.mermaid.enableTelemetryAllow Mermaid Preview to send anonymous preview failure analytics.
    preview.mermaid.showFeaturePopupsShow notifications when a feature has moved to the Mermaid extension.
    preview.mermaid.baseUrlBase URL used for extension usage analytics.
  9. Manage Mermaid Preview settings

    master

    The Mermaid Preview sidebar allows you to manage extension settings directly within the webview. You can toggle telemetry and feature popups, which updates the preview.mermaid configuration namespace in VS Code.

    Available settings via the sidebar:

    • enableTelemetry: Controls whether telemetry data is sent.
    • showFeaturePopups: Controls whether feature announcement popups are displayed.

    Note that the sidebar also reflects the global VS Code telemetry state (vscode.env.isTelemetryEnabled).

  10. Submit feedback via the Mermaid sidebar

    master

    The sidebar provides a feedback form to help improve the extension. When submitting, the following fields are required:

    • activity: The activity being performed.
    • frequency: How often the activity occurs.
    • details: A text description of the feedback.
    • email: Your contact email.

    Rate Limiting: Feedback submissions are rate-limited to once every 24 hours. If you attempt to submit more frequently, you will receive a warning message: "You can only send one feedback submission every 24 hours."