jghauser / follow-md-links.nvim

Easily follow markdown links with this neovim plugin
GNU General Public License v3.0
143 stars 16 forks source link

Doesn't follow file links, which have %20 to indicate spaces #20

Open ghost opened 10 months ago

ghost commented 10 months ago

So if a file name is Docker and Kubernetes.md, then it doesn't follow it.

- [Docker and Kubernetes](./Devops/Docker%20and%20Kubernetes.md)

This is a valid link, but it doesn't work. I create these files using nvim-tree, and would be great to be able to navigate through these files as well.

damca commented 10 months ago

I got spaces to work with the following. It relies on CommonMark specification. See this question. For example,

[here](<../parent with spaces/file with spaces.txt>)

I made the following change to the resolve_link function in the plugin. The primary change is in the last "else" clause which checks for <link> syntax.

@jghauser do you think this could be incorporated into the plugin?

local function resolve_link(link)
  local link_type
  local link2
  if link:sub(1, 1) == [[/]] then
    link_type = "local"
    link2 = link
  elseif link:sub(1, 1) == [[~]] then
    link_type = "local"
    link2 = os.getenv("HOME") .. [[/]] .. link:sub(2)
  elseif link:sub(1, 8) == [[https://]] or link:sub(1, 7) == [[http://]] then
    link_type = "web"
    link2 = link
  else
    link_type = "local"
    local linki = link:match("^<(.+)>$")
    if not linki then
      linki = link
    end
    link2 = fn.expand("%:p:h") .. [[/]] .. linki
  end
  return link2, link_type
end
jghauser commented 9 months ago

Is this solved by #19 ? Is there some use case for using %20 instead of blanks?

ghost commented 9 months ago

@jghauser No it is not. Still, if I have a file ./files/ansible notes.md, neovim doesn't record it as a link. It's not yellow highlighted as links usually are.

jghauser commented 9 months ago

Unfortunately, this isn't possible in the commonmark markdown specification (that the markdown treesitter parser implements). As the link in the above comment says, you should be able to have filenames with blanks as long as you wrap them in <>. So, the link would be [a link](<./files/ansible notes.md>). Is that an acceptable solution, @mesahilgautam?

ghost commented 9 months ago

@jghauser It does create the file(using lspsaga code actions), but for some reason, pressing enter over the link doesn't take me to the file. Although when on github, the link does work, (it adds that %20 in place of space.), but not locally. How I thought of it was, I press enter on the file, and it takes me to the file, doesn't matter whether the file exists or not (in the not case, it creates the file), or whether there is a space or not (for space the special syntax is exceptable, but it should take me to the file on pressing enter. The creation part has been solved by lspsaga codeactions.