feat(image): added support for mermaid diagrams in markdown

This commit is contained in:
Folke Lemaitre 2025-02-18 00:17:04 +01:00
parent 5a37d83897
commit f8e7942d6c
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
5 changed files with 54 additions and 1 deletions

View file

@ -129,6 +129,23 @@ function M.convert(src, opts)
args = { "-density", 300, "src", "-trim" },
})
return png, Spawn.multi(procs, opts)
elseif ext == "mmd" then
return png,
M.generate(png, vim.deepcopy(opts), {
cmd = "mmdc",
args = {
"-i",
src,
"-o",
png,
"-b",
"transparent",
"-t",
vim.o.background,
"-s",
Snacks.image.terminal.size().scale,
},
})
end
end
opts.args = {
@ -150,7 +167,7 @@ function M.convert(src, opts)
"-trim",
}
end
return png, Spawn.multi({ M.magick(src, png, opts) }, opts)
return png, M.magick(src, png, opts)
end
return M

View file

@ -261,6 +261,12 @@ function M.health()
Snacks.health.warn("`tectonic` or `pdflatex` is required to render LaTeX math equations")
end
if Snacks.health.have_tool("mmdc") then
Snacks.health.ok("Mermaid diagrams are supported")
else
Snacks.health.warn("`mmdc` is required to render Mermaid diagrams")
end
if env.supported then
Snacks.health.ok("your terminal supports the kitty graphics protocol")
elseif M.config.force then