-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[conf] Paste image by https://github.com/HakonHarnes/img-clip.nvim
- Loading branch information
1 parent
28d2573
commit f7432a6
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
-- Project-specific settings of img-clip.nvim. | ||
-- | ||
-- https://github.com/HakonHarnes/img-clip.nvim | ||
|
||
|
||
local function get_git_root() | ||
local dot_git_path = vim.fn.finddir(".git", ".;") | ||
return vim.fn.fnamemodify(dot_git_path, ":h") | ||
end | ||
|
||
local function get_images_dir() | ||
return get_git_root() .. "/_images" | ||
end | ||
|
||
local function trim_prefix(s, p) | ||
return (s:sub(0, #p) == p) and s:sub(#p+1) or s | ||
end | ||
|
||
return { | ||
default = { | ||
dir_path = get_images_dir, ---@type string | fun(): string | ||
file_name = "%Y-%m-%d_%H%M%S", ---@type string | fun(): string | ||
use_absolute_path = true, | ||
|
||
insert_mode_after_paste = false, ---@type boolean | fun(): boolean | ||
}, | ||
|
||
filetypes = { | ||
rst = { | ||
template = function(ctx) | ||
-- Get absolute path which relative to the top source directory. | ||
file_path = trim_prefix(ctx.file_path, get_git_root()) | ||
return "\n.. image:: " .. file_path .. "\n " .. ctx.cursor | ||
end, ---@type string | fun(context: table): string | ||
}, | ||
}, | ||
} |