feat(image): url_decode strings

This commit is contained in:
Folke Lemaitre 2025-02-16 09:09:23 +01:00
parent 14a1f32eaf
commit d41704f3da
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -108,9 +108,17 @@ function M.queries()
return ret
end
---@param str string
function M.url_decode(str)
return str:gsub("+", " "):gsub("%%(%x%x)", function(hex)
return string.char(tonumber(hex, 16))
end)
end
---@param buf number
---@param src string
function M.resolve(buf, src)
src = M.url_decode(src)
local file = vim.fs.normalize(vim.api.nvim_buf_get_name(buf))
local s = Snacks.image.config.resolve and Snacks.image.config.resolve(file, src) or nil
if s then