mermaid-viewer-cli
v1.0.4
Published
> β¨ A sleek Node.js CLI tool to **view, edit, and export Mermaid diagrams** β powered by π `commander`, β‘ `TailwindCSS`, and π§ `Mermaid.js`.
Downloads
17
Maintainers
Readme
π§ Mermaid Diagram Viewer CLI
β¨ A sleek Node.js CLI tool to view, edit, and export Mermaid diagrams β powered by π
commander, β‘TailwindCSS, and π§Mermaid.js.
πΈ Screenshot

π¨ Features
- β Beautiful HTML Preview β dark mode using TailwindCSS π
- β Monaco Editor β professional code editor with syntax highlighting π»
- β Split View β source on the left, live-rendered diagram on the right πͺ
- β Live Editing β instantly re-render as you type βοΈ
- β Multiple Themes β Dark, Light, Forest, and Neutral themes π¨
- β Sample Library β 14+ pre-built diagram examples to learn from π
- β Zoom Controls β smooth control for detailed diagrams π
- β Export Options β download as SVG πΌοΈ, PNG πΈ, or MMD source πΎ
- β Keyboard Shortcuts β save & refresh with ease β¨οΈ
- β Stdin Support β pipe diagrams from other commands π
- β Draggable Splitter β resize panes to your preference βοΈ
π Installation
npm install -g mermaid-viewer-clior run directly with npx:
npx mermaid-viewer-cli -f diagram.mmdβοΈ Usage
π§ Basic Commands
From a file:
mermaid-viewer -f your-diagram.mmdFrom stdin (auto-detected):
echo "graph TD; A-->B" | mermaid-viewer
cat diagram.mmd | mermaid-viewer -o output.html
# Using heredoc
mermaid-viewer -o chart.html <<EOF
graph TD
A[Start] --> B[Process]
B --> C[End]
EOFPipe from other commands:
# From a script
./generate-diagram.sh | mermaid-viewer --open
# From curl
curl -s https://example.com/diagram.mmd | mermaid-viewerπ Options
| Option | Description |
| ----------------------- | ------------------------------------------------ |
| -f, --file <path> | Path to the Mermaid file (.mmd or .txt) |
| -o, --out-html <path> | Output HTML file (default: mermaid-diagram.html) |
| -t, --title <text> | Title for HTML page (default: Mermaid Diagram) |
| --open | Open generated HTML in browser automatically |
Note: The tool auto-detects stdin input. If you pipe data, you don't need any special flag!
π§βπ» Live Editing
- π‘ The left pane is a Monaco editor with Mermaid syntax highlighting.
- πͺ The right pane shows the rendered diagram in real time.
- π Changes auto-render after 800ms of inactivity (debounced).
- π Load sample diagrams from the dropdown menu to learn syntax.
β¨οΈ Keyboard Shortcuts
| Shortcut | Action |
| --------------- | ------------------------------- |
| Ctrl+S / Cmd+S | Download Mermaid source (.mmd) |
| Ctrl+R / Cmd+R | Re-render diagram |
| Ctrl+B / Cmd+B | Toggle minimap in editor |
π€ Export Options
At the top-right corner, you'll find export buttons:
- πΌοΈ Download SVG β for scalable vector diagrams
- πΈ Download PNG β for raster images (high resolution)
- πΎ Download MMD β save the Mermaid source code
π¨ Theme Support
Choose from 4 beautiful themes:
- π Dark (default)
- βοΈ Light
- π² Forest
- βͺ Neutral
Switch themes using the dropdown menu and see your diagram update instantly!
π Sample Library
Load pre-built examples to learn Mermaid syntax:
- Account Merge Flow
- Apex Class Writing Flow
- Git Operations Flow
- ReactJS Development Flow
- Performance Testing Flow
- And 10+ more!
π Examples
Example 1: Simple Flowchart
graph TD
A[Start] --> B{Is it working?}
B -->|Yes| C[Awesome! π]
B -->|No| D[Check your syntax π§©]
D --> BSave it as example.mmd, then run:
mermaid-viewer -f example.mmd --openExample 2: Salesforce Sandboxes Flow
flowchart TB
%% Colors
classDef dev fill:#4ade80,stroke:#166534,color:#fff; %% green
classDef int fill:#60a5fa,stroke:#1e3a8a,color:#fff; %% blue
classDef qa fill:#fbbf24,stroke:#92400e,color:#fff; %% amber
classDef uat fill:#f472b6,stroke:#9d174d,color:#fff; %% pink
classDef preprod fill:#a78bfa,stroke:#4c1d95,color:#fff; %% purple
classDef prod fill:#ef4444,stroke:#7f1d1d,color:#fff; %% red
%% Nodes
DEV1["Dev Sandbox 1"]
DEV2["Dev Sandbox 2"]
DEV3["Dev Sandbox 3"]
INT["Integration Sandbox"]
QA["QA Sandbox"]
UAT["UAT Sandbox"]
PREPROD["Pre-Prod Sandbox"]
PROD["Production Org"]
%% Flow
DEV1 --> INT
DEV2 --> INT
DEV3 --> INT
INT --> QA
QA --> UAT
UAT --> PREPROD
PREPROD --> PROD
%% Apply classes
class DEV1,DEV2,DEV3 dev
class INT int
class QA qa
class UAT uat
class PREPROD preprod
class PROD prodPipe it directly:
cat salesforce-flow.mmd | mermaid-viewer -t "Salesforce Sandboxes" --openExample 3: Generate from Script
#!/bin/bash
# generate-diagram.sh
echo "graph LR"
echo " A[CI/CD Pipeline]"
echo " A --> B[Build]"
echo " B --> C[Test]"
echo " C --> D[Deploy]"Run:
./generate-diagram.sh | mermaid-viewer -o pipeline.htmlπ§Ύ UI Layout
+-------------------------------------------+-------------------------------------------+
| π Monaco Editor (Mermaid Source) | π§© Live Diagram Preview |
| | |
| - Syntax highlighting | - Real-time rendering |
| - Line numbers | - Zoom controls |
| - Minimap | - Pan & scroll |
| - Auto-complete | - Grid background |
|-------------------------------------------|-------------------------------------------|
| Status Bar: Stats, Render time, Node count |
+--------------------------------------------------------------------------------------+π§ Advanced Usage
Pipeline Integration
# Generate diagram from database query
psql -c "SELECT * FROM workflow" | \
awk '{print "graph TD; " $1 "-->" $2}' | \
mermaid-viewer -o db-flow.html
# From API response
curl -s https://api.example.com/diagram | \
jq -r '.mermaid' | \
mermaid-viewer --openContinuous Preview
# Watch file and regenerate on changes
watch -n 2 'cat diagram.mmd | mermaid-viewer -o preview.html'π§βπ¨ Future Enhancements
- π§ Multiple tabs for multiple diagrams
- π Auto-save + diagram history snapshots
- π Web server mode for live collaboration
- π± Responsive mobile view
- π― Direct GitHub integration
π License
MIT License - feel free to use this in your projects!
π§‘ Credits
Built with β€οΈ by Mohan Chinnappan
Happy Diagramming! π¨π
