nvim-telekasten / telekasten.nvim

A Neovim (lua) plugin for working with a markdown zettelkasten / wiki and mixing it with a journal, based on telescope.nvim
MIT License
1.42k stars 91 forks source link

[BUG] Image preview not working, possibly incorrect path handling #174

Open avonmoll opened 2 years ago

avonmoll commented 2 years ago

Please confirm

Describe the bug "File not found" error when trying to preview image under link. Also, when browsing media, the Telescope preview pane shows an error message (which I think comes from catimg): stb_image_error: No such file or directory.

To Reproduce Steps to reproduce the behavior:

  1. nvim first-note.md (cwd is /Users/me/zettelkasten)
  2. Hover over the link
  3. Call require('telekasten').preview_img()
  4. Neovim outputs File not found: /Users/me/zettelkasten/img/pasted_img_20221014131739.png

first-note.md:

...
- ![](img/pasted_img_20221014131739.png)

relevant config bits:

local home = vim.fn.expand("~/zettelkasten")
require("telekasten").setup({
...
    home = home,
...
    img_subdir = "img",
    image_link_style = "markdown",
    media_previewer = "catimg-previewer",
...
})

Expected behavior A preview of the image should be shown. In fact, the following works (with the exact same path listed in the "File not found" error): catimg /Users/me/zettelkasten/img/pasted_img_20221014131739.png.

Operating system (please complete the following information):

dmytrodubinin commented 2 years ago

The same problem. MarkdownPreview shows image, but telekasten output file not found

lambtho12 commented 1 year ago

@renerocksai , whenever you have time, could you look into this issue a bit? Its been 30min and I still cannot understand how/why you implemented this like that.

I solved a first issue where the img/ was duplicated in the path if the link to the file was ![](img/file.jpg). However, telescope-media-files is still not being called properly. This is because in line 998 we expect a script of some sort for this previewer. This scrip was never part of the repo. As you are the one that made this function, maybe you have it on your machine or would be able to fix it anyway... I think it is the last stuff to do to (hopefully) close this issue.

renerocksai commented 1 year ago

Hi @lambtho,

The way it works is as follows: another plugin, telescope-media-files.nvim, provides the image previewer. Hence, we need to find the path to the previewer script. Our own telekasten.lua script is in .../telekasten.nvim/lua/telekasten.lua. With ":h:h:h" we go up 3 directories from there, landing at ".../", one directory above the telekasten plugin directory. To that, we append "telescope-media-files.nvim" and get the telescope-media-files plugin directory. When we append "/scripts/vimg" to that, we have the path to the previewer script of the other plugin.

Hope this helps; I am trying to recover from a cold; when I'm fit again I shall have a look at why things might not be working. I suspect it might have to do with the wrong cwd being passed to the previewer or the path to the img not being correct, relative to the cwd of the called previewer.

On Sun, Feb 5, 2023 at 3:45 PM lambtho @.***> wrote:

@renerocksai https://github.com/renerocksai , whenever you have time, could you look into this issue a bit? Its been 30min and I still cannot understand how/why you implemented this like that.

I solved a first issue where the img/ was duplicated in the path if the link to the file was . However, telescope-media-files is still not being called properly. This is because in line 998 https://github.com/renerocksai/telekasten.nvim/blob/9cbbbb697099ed1e772861b208dc1068b8b1ec07/lua/telekasten.lua#L998 we expect a script of some sort for this previewer. This scrip was never part of the repo. As you are the one that made this function, maybe you have it on your machine or would be able to fix it anyway... I think it is the last stuff to do to (hopefully) close this issue.

— Reply to this email directly, view it on GitHub https://github.com/renerocksai/telekasten.nvim/issues/174#issuecomment-1417990469, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHLWBJ7PBZJ3USULNLE6B2LWV64JJANCNFSM6AAAAAARIKPGAQ . You are receiving this because you were mentioned.Message ID: @.***>

lambtho12 commented 1 year ago

Ah, I get it now. So I actually think I fixed the issue with my commit yesterday. There was indeed an issue with the path. It should be all good now. Although the fix is a bit hacky and could probably be improved.


What screwed things up is that in my case is that Telekasten plugin is not installed in the same spot as other plugins. I like to have the plugins I actively develop in a local repository (~/nvim-plugins). Using lazy.nvim as my plugin manager it is then very easy to switch between the dev version and the github one. Anyway, that means that the h:h:hstuff used to go into telescope-media-files does not work and the script cannot be found. It would probably be best to find a more robust way to call this plugin. I will open an issue for that and close this one, as commit https://github.com/renerocksai/telekasten.nvim/commit/9cbbbb697099ed1e772861b208dc1068b8b1ec07 likely fixed the problem

lambtho12 commented 1 year ago

Actually I am reopening that. Hardcoding img/ is not ideal to say the least. If people were to have other images repositories such as images/the current "fix" would not work.

I shall revisit the patch soon to provide a proper way to figure out the actual path.