refactor(neovim): Markdown image pasting and rendering improvements

This commit is contained in:
Pratik Tripathy
2025-07-24 16:50:54 +05:30
parent c1ee0c269e
commit 3bea86537a
2 changed files with 19 additions and 9 deletions

View File

@@ -115,6 +115,30 @@ return {
default = { default = {
use_absolute_path = false, ---@type boolean use_absolute_path = false, ---@type boolean
relative_to_current_file = false, ---@type boolean relative_to_current_file = false, ---@type boolean
use_cursor_in_template = true,
-- Generic config, specifies inside `filetypes` section below
dir_path = function()
local root = vim.fn.FindRootDirectory()
if root ~= "" then
return root .. "/.artifacts/img"
else
return vim.fn.expand("%:p:h") .. "/.artifacts/img"
end
end,
prompt_for_file_name = true, ---@type boolean
file_name = "%y%m%d-%H%M%S", ---@type string
extension = "webp", ---@type string
process_cmd = "convert - -quality 75 webp:-", ---@type string
},
filetypes = {
markdown = {
url_encode_path = true, ---@type boolean
template = "![$CURSOR](./$FILE_PATH)",
dir_path = function() dir_path = function()
local root = vim.fn.FindRootDirectory() local root = vim.fn.FindRootDirectory()
@@ -125,26 +149,12 @@ return {
end end
end, end,
prompt_for_file_name = false, ---@type boolean file_name = "%y%m%d-%H%M%S",
file_name = "%y%m%d-%H%M%S", ---@type string
-- Format of the image to be saved: must convert it as well
-- https://stackoverflow.com/a/27269260
extension = "webp", ---@type string extension = "webp", ---@type string
process_cmd = "convert - -quality 75 webp:-", ---@type string process_cmd = "convert - -resize 800x -quality 85 webp:-", ---@type string
},
filetypes = {
markdown = {
url_encode_path = true, ---@type boolean
-- The template is what specifies how the alternative text and path
-- of the image will appear in your file
-- I want to use blink.cmp to easily find images with the LSP, so adding ./
template = "![Image](./$FILE_PATH)",
-- template = "![$FILE_NAME]($FILE_PATH)", ---@type string
}, },
-- TODO: Adapt for HTMLs
-- html = {},
}, },
}, },
-- TIP: Use :PasteImage -- TIP: Use :PasteImage

View File

@@ -41,7 +41,7 @@ return {
max_width = 80, max_width = 80,
max_height = 68, max_height = 68,
}, },
img_dirs = { "img", "images", "assets", "static", "public", "media", "attachments", ".artifacts/img" }, img_dirs = { "img", "images", "assets", "static", "public", "media", "attachments", ".artifacts/img", ".artifacts", ".assets" },
}, },
lazygit = { lazygit = {
enabled = true, enabled = true,