Skip to content

feat: add mermaid diagram ASCII rendering support#904

Open
tawago wants to merge 1 commit intocharmbracelet:masterfrom
tawago:mermaid-support
Open

feat: add mermaid diagram ASCII rendering support#904
tawago wants to merge 1 commit intocharmbracelet:masterfrom
tawago:mermaid-support

Conversation

@tawago
Copy link
Copy Markdown

@tawago tawago commented Mar 26, 2026

aiming to close #342

Summary

Adds support for rendering mermaid code blocks as ASCII art diagrams, addressing #342.

  • Integrates mermaid-ascii library for Go-native rendering
  • Supports flowcharts (graph LR/TD/RL/BT) and sequence diagrams
  • Graceful fallback: preserves original code block when diagram type or feature is unsupported
  • Single --mermaid flag (enabled by default, use --mermaid=false to disable)
  • Works in both CLI and TUI modes

Example

graph LR
    A[Start] --> B{Decision}
    B -->|Yes| C[OK]
    B -->|No| D[Cancel]
Loading

Renders as:

┌───────┐     ┌──────────┐
│ Start │────▶│ Decision │
└───────┘     └────┬─────┘
                   │
        ┌──────────┴──────────┐
        ▼                     ▼
   ┌────────┐            ┌─────────┐
   │   OK   │            │ Cancel  │
   └────────┘            └─────────┘

Unsupported Features (graceful fallback)

The following are detected and fall back to showing the original code block:

  • Diagram types: pie, gantt, classDiagram, stateDiagram, erDiagram, etc.
  • Sequence features: loop, alt, opt, par, Note, activate/deactivate

Test plan

  • Unit tests for mermaid package (10 test cases)
  • go test ./... passes
  • go vet ./... passes

@tawago tawago requested a review from a team as a code owner March 26, 2026 08:20
@tawago tawago requested review from meowgorithm and raphamorim and removed request for a team March 26, 2026 08:20
Adds support for rendering mermaid code blocks as ASCII art diagrams
using the mermaid-ascii library. This addresses issue charmbracelet#342.

Features:
- Flowchart (graph LR/TD/RL/BT) rendering
- Sequence diagram rendering
- Graceful fallback for unsupported diagram types and features
- Single --mermaid flag (enabled by default)
- Works in both CLI and TUI modes

The implementation detects unsupported features (loops, notes, etc.)
and preserves the original code block rather than producing broken
output.

Closes charmbracelet#342

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for mermaid, to render flow diagrams

1 participant