kais-radwan
ascii-mermaid
TypeScript

Neovim plugin that renders Mermaid diagrams as inline ASCII art using virtual text

Last updated Jun 20, 2026
36
Stars
4
Forks
1
Issues
0
Stars/day
Attention Score
30
Language breakdown
TypeScript 72.6%
Lua 15.3%
JavaScript 11.7%
Shell 0.3%
Makefile 0.1%
โ–ธ Files click to expand
README

ascii-mermaid

A Neovim plugin that renders Mermaid diagram code blocks in Markdown files as inline ASCII/Unicode art using virtual text. No browser, no external services -- just plain text diagrams rendered directly in your editor.

The rendering engine is pure TypeScript (zero dependencies) that runs via Node.js, invoked asynchronously from Lua so it never blocks the editor.

What it looks like

A mermaid code block like this:

~~~markdown

graph TD     A[Start] --> B{Decision}     B -->|Yes| C[OK]     B -->|No| D[Error]     C --> E[End]     D --> E
~~~

Renders inline as:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚          โ”‚
โ”‚  Start   โ”‚
โ”‚          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜
      โ”‚
      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚          โ”‚
โ”‚ Decision โ”œโ”€โ”€โ”€Noโ”€โ”€โ”€โ”€โ”
โ”‚          โ”‚         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜         โ”‚
     Yes             โ”‚
      โ”‚              โ”‚
      โ–ผ              โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚          โ”‚     โ”‚       โ”‚
โ”‚    OK    โ”‚     โ”‚ Error โ”‚
โ”‚          โ”‚     โ”‚       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”˜
      โ”‚              โ”‚
      โ–ผ              โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”‚
โ”‚          โ”‚         โ”‚
โ”‚   End    โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Supported diagram types

Flowcharts -- graph TD, flowchart LR, all four directions (TD, LR, BT, RL), subgraphs, 13 node shapes, edge labels, chaining, parallel edges.

State diagrams -- stateDiagram-v2, composite states, start/end pseudostates, labeled transitions.

Sequence diagrams -- sequenceDiagram, participants, actors, solid/dashed arrows, activation, blocks (loop, alt, opt, par, critical, break).

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”
 โ”‚ Alice โ”‚     โ”‚ Bob โ”‚
 โ””โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”ฌโ”€โ”€โ”˜
     โ”‚   Hello    โ”‚
     โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ
     โ”‚  Hi back   โ”‚
     โ—€โ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ•Œโ”‚
 โ”Œโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”ดโ”€โ”€โ”
 โ”‚ Alice โ”‚     โ”‚ Bob โ”‚
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”˜

Class diagrams -- classDiagram, multi-section boxes (name/attributes/methods), visibility markers, UML relationship notation (inheritance, composition, aggregation), namespaces.

ER diagrams -- erDiagram, entity boxes with typed attributes (PK/FK/UK), crow's foot cardinality notation, identifying/non-identifying relationships.

Gantt charts -- gantt, sections, task bars with date ranges, dependencies (after), status tags (done, active, crit, milestone).

Project Plan
  Design
    Mockups  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  01-01 -> 01-08
    Review   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  01-08 -> 01-11
  Dev
    Coding   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ  01-11 -> 01-25

Pie charts -- pie, horizontal bar representation with proportional widths and percentages, optional showData for raw values.

Dogs   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ                        44.4%
  Cats   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ                             33.3%
  Fish   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ                                 22.2%

Timeline diagrams -- timeline, vertical layout with boxed periods and tree-branching events, sections.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ 2020 โ”‚
    โ””โ”€โ”€โ”€โ”ฌโ”€โ”€โ”˜
        โ””โ”€โ”€ Event A
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ 2021 โ”‚
    โ””โ”€โ”€โ”€โ”ฌโ”€โ”€โ”˜
        โ”œโ”€โ”€ Event B
        โ””โ”€โ”€ Event C

Requirements

  • Neovim >= 0.9
  • Node.js >= 18

Installation

The pre-built JavaScript engine is included in the repository -- no build step required.

lazy.nvim

{
  "kais-radwan/ascii-mermaid",
  ft = "markdown",
  opts = {},
}

packer.nvim

use {
  "kais-radwan/ascii-mermaid",
  config = function()
    require("ascii-mermaid").setup()
  end,
  ft = "markdown",
}

vim-plug

Plug 'kais-radwan/ascii-mermaid'

Then in your init.lua:

require("ascii-mermaid").setup()

Manual

Clone the repository into your Neovim packages directory:

git clone https://github.com/kais-radwan/ascii-mermaid \
  ~/.local/share/nvim/site/pack/plugins/start/ascii-mermaid

Then add to your config:

require("ascii-mermaid").setup()

Configuration

require("ascii-mermaid").setup({
  auto = true,              -- auto-render on BufEnter and CursorHold
  use_ascii = false,        -- false = Unicode box-drawing, true = ASCII (+,-,|,>)
  debounce_ms = 500,        -- debounce delay for CursorHold re-renders
  padding_x = 2,            -- horizontal padding inside node boxes
  padding_y = 1,            -- vertical padding inside node boxes
  display_mode = "replace", -- "inline", "replace", "hybrid", or "readonly"
  hybrid_threshold = 15,    -- line count threshold for hybrid mode
})

Display modes

  • inline -- Rendered diagram appears as virtual text below the code block. Source code remains visible and editable.
  • replace -- Diagram overlays the source code block. Move your cursor into the block to reveal the source; move away to see the diagram again.
  • hybrid -- Uses replace mode for short blocks (under hybrid_threshold lines) and inline mode for longer ones.
  • readonly -- Like replace mode, but the source code is never revealed. Use :MermaidClear to get back to source.

Commands

| Command | Description | |---|---| | :MermaidRender | Toggle rendering for the current buffer | | :MermaidRenderAll | Force re-render all blocks (clears cache) | | :MermaidClear | Clear all rendered diagrams | | :MermaidStyle ascii\|unicode | Switch between ASCII and Unicode rendering | | :MermaidMode inline\|replace\|hybrid\|readonly | Switch display mode |

Building from source

Only needed if you modify the TypeScript engine:

cd ts
npm install    # one-time: installs tsup + typescript
npm run build  # outputs to ts/dist/

Run tests:

make test        # build + TS unit tests + Neovim integration tests
make test-ts     # TypeScript unit tests only
make test-nvim   # Neovim integration tests only

Architecture

Two-layer design:

  • TypeScript engine (ts/src/) -- Pure TypeScript, zero runtime dependencies. Parses Mermaid text and renders to ASCII/Unicode strings. Flowcharts and state diagrams use a grid-based layout with A* pathfinding for edge routing. Each other diagram type has a specialized renderer.
  • Neovim Lua plugin (lua/ascii-mermaid/) -- Detects mermaid code blocks via tree-sitter (with regex fallback), shells out to Node.js asynchronously via vim.system(), and displays results as virtual text using extmarks.
See the docs/ directory for detailed architecture documentation.

Acknowledgements

The core rendering engine is based on beautiful-mermaid by lukilabs. This project extends and adapts that engine with additional diagram type support, a Neovim integration layer, and multiple display modes.

License

MIT

๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท kais-radwan/ascii-mermaid ยท Updated daily from GitHub