HakonHarnes / img-clip.nvim

Effortlessly embed images into any markup language, like LaTeX, Markdown or Typst
MIT License
443 stars 7 forks source link

one dir_path for one markdown file #66

Closed LintaoAmons closed 4 months ago

LintaoAmons commented 4 months ago

Is your feature request related to a problem? Please describe. I want move the markdown file from one place to another place. Those images should also go with the markdown files, but since current we put all image inside one assets folder, if we have multiple markdown files in same directory, I need to filter out the images for that markdown file manually. So I was thinking maybe the dir_path could have an option to create specific dir to place the images for that specific markdown file.

e.g. I create a markdown file named test.md --> when paste an image into the test.md file, the image saved to file_dir/.asset_test folder. The file_dir is the directory where the markdown file is located(since sometimes people like me would just open another note outside current pwd, so I think it's nice to put it at the same location with the markdown file instead of pwd)

HakonHarnes commented 4 months ago

This should already be doable. Try the following configuration:

opts = {
  filetypes = {
    markdown = {
      dir_path = function()
        return "asset_" .. vim.fn.expand("%:t:r")
      end,
    },
  },
},

Any option can be dynamically configured using Lua functions :)

LintaoAmons commented 4 months ago

Oh, that's great, I didn't noticed this in the README doc. You have type hint all the options as string

LintaoAmons commented 4 months ago

Oh, one more thing is the dir_path prefix, since the dir_path is a relative path. If I remember correctly, the prefix is pwd, how could I change it to the path where the markdown file is located at.

HakonHarnes commented 4 months ago

Oh, one more thing is the dir_path prefix, since the dir_path is a relative path. If I remember correctly, the prefix is pwd, how could I change it to the path where the markdown file is located at.

You can enable the relative_to_current_file option, i.e.:

opts = {
  filetypes = {
    markdown = {
      relative_to_current_file = true,
      dir_path = function()
        return "asset_" .. vim.fn.expand("%:t:r")
      end,
    },
  },
},

You have type hint all the options as string

Thanks for pointing that out. I should probably change it to string | func or similar for clarity.