Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/3rd/diagram.nvim

Diagrams as code in Neovim.
https://github.com/3rd/diagram.nvim

neovim neovim-plugin

Last synced: 2 days ago
JSON representation

Diagrams as code in Neovim.

Awesome Lists containing this project

README

        

# diagram.nvim

A Neovim plugin for rendering diagrams, powered by [image.nvim](https://github.com/3rd/image.nvim).
\
You'll **need to set up [image.nvim](https://github.com/3rd/image.nvim)** to use this plugin, and either [Kitty](https://github.com/kovidgoyal/kitty) or [Überzug++](https://github.com/jstkdng/ueberzugpp).

### Integrations & renderers

The plugin has a generic design with pluggable **renderers** and **integrations**.
\
Renderers take source code as input and render it to an image, often by calling an external process.
\
Integrations read buffers, extract diagram code, and dispatch work to the renderers.

| Integration | Supported renderers |
| ----------- | --------------------------- |
| `markdown` | `mermaid`, `plantuml`, `d2` |
| `neorg` | `mermaid`, `plantuml`, `d2` |

| Renderer | Requirements |
| ---------- | ------------------------------------------------- |
| `mermaid` | [mmdc](https://github.com/mermaid-js/mermaid-cli) |
| `plantuml` | [plantuml](https://plantuml.com/download) |
| `d2` | [d2](https://d2lang.com/) |

### Installation

With **lazy.nvim**:

```lua
{
"3rd/diagram.nvim",
dependencies = {
"3rd/image.nvim",
},
opts = { -- you can just pass {}, defaults below
renderer_options = {
mermaid = {
background = nil, -- nil | "transparent" | "white" | "#hex"
theme = nil, -- nil | "default" | "dark" | "forest" | "neutral"
scale = 1, -- nil | 1 (default) | 2 | 3 | ...
},
plantuml = {
charset = nil,
},
d2 = {
theme_id = nil,
dark_theme_id = nil,
scale = nil,
layout = nil,
sketch = nil,
},
}
},
},
```

### Usage

To use the plugin, you need to set up the integrations and renderers in your Neovim configuration. Here's an example:

```lua
require("diagram").setup({
integrations = {
require("diagram.integrations.markdown"),
require("diagram.integrations.neorg"),
},
renderer_options = {
mermaid = {
theme = "forest",
},
plantuml = {
charset = "utf-8",
},
d2 = {
theme_id = 1,
},
},
})
```

### API

The plugin exposes the following API functions:

- `setup(opts)`: Sets up the plugin with the given options.
- `get_cache_dir()`: Returns the root cache directory.

```