Skip to content

Better Mermaid Diagram Tools in Marktext #4363

Closed

Description

@LuxusIX

Summary

Add interactive tools to inspect, navigate, and export Mermaid diagrams in Marktext, improving usability for complex schemas.

Problem it solves

Currently, Marktext only renders Mermaid diagrams statically. Users cannot:

  • Zoom, pan, or collapse large diagrams.
  • Inspect nodes/edges for details (e.g., properties, connections).
  • Export diagrams as JSON/CSV or images for further use.
  • Access text summaries for screen readers or accessibility.

This limits Marktext’s usefulness for developers, architects, and technical writers who rely on Mermaid for documentation.

Proposed solution

Introduce a set of tools for Mermaid diagrams in the preview pane:

  1. Interactive Viewer: Zoom, pan, and collapse/expand nodes.
  2. Inspector Panel: Click on nodes/edges to view properties (ID, type, connections).
  3. Export Options: Save diagrams as JSON, CSV, or images (PNG/SVG).
  4. Accessibility: Generate text summaries and support keyboard navigation.

Alternatives considered [optional]

Not really

Additional context [optional]

Image

Activity

  1. added
    🦄 feature request
    on Jun 4, 2026
  2. Jocs commented on Sep 25, 2026

    @Jocs
    Member

    Thanks for the write-up — it pointed at a real gap, and a bigger one than the issue describes: a diagram block had no hover toolbar at all, so it never even got the edit and delete actions that math and HTML blocks have had for years.

    #5554 implements this. Taking your four points in order:

    1. Interactive viewer — done, except node collapsing. Hovering a diagram now shows a toolbar; the magnifier opens it full-screen, where you can zoom (wheel, + / -, buttons), pan (drag or arrow keys), fit to the window (0) or go back to actual size (1). Esc closes it. Collapsing and expanding nodes is not included, for the same reason as point 2.

    Zooming is deliberately confined to the full-screen view rather than the inline block: wheel-zoom on a block inside a scrolling document either hijacks the scroll or fights it.

    2. Inspector panel — not implemented, and I'd argue it shouldn't be. Mermaid's public API gives only { diagramType } back from parse(). Reaching the actual vertices and edges means going through the deprecated, internal mermaidAPI, whose shape differs per diagram type and can change in any release. And it only ever answers for mermaid — MarkText also renders Vega-Lite, PlantUML, flowchart.js and js-sequence-diagrams, none of which expose a comparable model (PlantUML doesn't even render locally; the picture comes back from a server). Building this means MarkText owning a semantic model per diagram type per renderer, which is a lot of surface to maintain for a feature that belongs closer to a diagramming tool than to a markdown editor.

    3. Export — images done, JSON/CSV not. From the full-screen view a diagram can be saved as SVG, saved as PNG, or copied to the clipboard as an image, so it can go straight into a chat or a slide without exporting the whole document. All five diagram types are covered, in both the light and the dark theme. JSON/CSV is the same problem as point 2 — it needs the structure that isn't available.

    4. Accessibility — partly. A rendered diagram is now exposed as an image with an accessible name, taken from mermaid's own accTitle / accDescr when the diagram declares them and falling back to a localized label otherwise. The full-screen view is a real role="dialog": it takes focus when it opens, returns it when it closes, and its whole zoom/pan set is on the keyboard. What is not there is per-node keyboard navigation or a generated prose summary of the graph — again, both need the semantic model from point 2.

    One clarification that may be useful, since the request is framed around Mermaid: the Mermaid library itself provides none of this. I checked 11.15 (what we ship) and the current 12.0 — panZoom, zoomIn, zoomOut and fullscreen appear zero times in its type surface and in the upstream config schema. The toolbar people recognise from the Mermaid Live Editor belongs to that application, which depends on svg-pan-zoom separately. (If you grep the bundled mermaid.min.js you will find "panzoom" — that's Cytoscape, vendored in for the architecture/mindmap layouts, and it neither is exported nor applies to render() output.) So the viewer here is MarkText's own, not something that was sitting unused upstream.

    Where upstream did already have something, it's used rather than reimplemented: Vega-Lite's own export, PlantUML's server-side /svg/ and /png/ endpoints, and Mermaid's htmlLabels switch and accessibility attributes.

    This issue will close when #5554 lands. If the inspector matters to you for mermaid specifically, please open a separate issue for it — it's a different kind of feature with a different cost, and it deserves to be discussed on its own terms rather than closed silently along with the rest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🦄 feature request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions