snacks.nvim
snacks.nvim copied to clipboard
feature: Allow providing image src through TSNode metadata
Did you check the docs?
- [x] I have read all the snacks.nvim docs
Is your feature request related to a problem? Please describe.
I want to add image rendering support with Snacks to https://github.com/nvim-orgmode/orgmode, but due to parser limitation, I'm not able to match the exact node that contains the image URL.
Describe the solution you'd like
I'd like to be able to provide an image URL through the TSNode metadata via custom directive, and have Snacks pick that value up if provided. Basically, this diff works for me:
diff --git a/lua/snacks/image/doc.lua b/lua/snacks/image/doc.lua
index 4910a06..8f0c428 100644
--- a/lua/snacks/image/doc.lua
+++ b/lua/snacks/image/doc.lua
@@ -130,7 +130,9 @@ function M.find(buf, from, to)
},
}
img.pos[1] = math.min(img.pos[1], vim.api.nvim_buf_line_count(buf))
- if ctx.src then
+ if ctx.pos.meta.image then
+ img.src = ctx.pos.meta.image
+ elseif ctx.src then
img.src = vim.treesitter.get_node_text(ctx.src.node, buf, { metadata = ctx.src.meta })
end
if ctx.content then
I'm ok to provide with any name you prefer, but the idea is to provide image src through the node metadata.
Describe alternatives you've considered
I thought of setting up custom autocmds and render images manually with Snacks.image.placement
, but then the user's customization would not apply. I'd prefer to integrate in the way as suggested above.
Additional context
No response