Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lua/snacks/image/convert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ local commands = {
end
end,
},
d2 = {
cmd = {
cmd = "d2",
args = Snacks.image.config.convert.d2,
},
file = function(convert, ctx)
return convert:tmpfile(vim.o.background .. ".png")
end,
},
mmd = {
cmd = {
cmd = "mmdc",
Expand Down
14 changes: 13 additions & 1 deletion lua/snacks/image/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,20 @@ local defaults = {
---@class snacks.image.convert.Config
convert = {
notify = false, -- show a notification on error
---@class snacks.image.d2.Opts
d2_opts = {
layout = "dagre", -- default layout engine
theme = nil
},
---@type snacks.image.args
d2 = function ()
local opts = M.config.convert.d2_opts
local theme = opts.theme or (vim.o.background == "light" and "0" or "200")
local layout = M.config.convert.d2_opts.layout
return { "{src}", "{file}", "--layout", layout, "--theme", theme, "--scale", "{scale}" }
end,
---@type snacks.image.args
mermaid = function()
mermaid = function ()
local theme = vim.o.background == "light" and "neutral" or "dark"
return { "-i", "{src}", "-o", "{file}", "-b", "transparent", "-t", theme, "-s", "{scale}" }
end,
Expand Down
8 changes: 8 additions & 0 deletions queries/markdown/images.scm
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@
(#set! injection.language "mermaid")
(#set! image.ext "chart.mmd")
) @image

(fenced_code_block
(info_string (language) @lang)
(#eq? @lang "d2")
(code_fence_content) @image.content
(#set! injection.language "d2")
(#set! image.ext "chart.d2")
) @image
10 changes: 10 additions & 0 deletions tests/image/test-d2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
```d2
good chips: {
doritos
ruffles
}
bad chips.lays
bad chips.pringles

chocolate.chip.cookies
```