A Neovim plugin for rendering diagrams, powered by image.nvim.
You'll need to set up image.nvim to use this plugin, and either Kitty or Überzug++.
diagram-nvim-demo.mp4
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 |
plantuml |
plantuml |
d2 |
d2 |
With lazy.nvim:
{
"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,
},
}
},
},
To use the plugin, you need to set up the integrations and renderers in your Neovim configuration. Here's an example:
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,
},
},
})
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.