Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghost opened this issue Dec 22, 2023 · 5 comments
Open

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

ghost opened this issue Dec 22, 2023 · 5 comments

Comments

@ghost
Copy link

ghost commented Dec 22, 2023

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
Copy link

damca commented Jan 2, 2024

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
Copy link
Owner

jghauser commented Feb 11, 2024

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

@jghauser jghauser changed the title Doesn't follow file links, which have spaces in the name Doesn't follow file links, which have %20 to indicate spaces Feb 11, 2024
@ghost
Copy link
Author

ghost commented Feb 11, 2024

@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
Copy link
Owner

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
Copy link
Author

ghost commented Feb 11, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants