Open mrossinek opened 2 years ago
bump
It's useful if you rely on images and other non-norg files and you need to open them using xdg-open.
{file:///abosulute/path}
{file://:path:} # this can use the capabilities of the :path: target
Hope to see this feature.
Links to non norg files are written as {/ path/to/file}
. You see the /
at the front which means a normal file path.
Please read {# File Location}
section in the specification for more detials. https://github.com/nvim-neorg/norg-specs/blob/51aab3dfd3bdf1d7ebdd2648d2e418ddd8d9ce2c/1.0-specification.norg#L1343
Absolute paths also works exactly the same with {/ /etc/passwd}
or {/ C:/Users/...}
.
The {/ path/to/file}
link only works for text files.
@brglng what are you trying to open b/c this works perfectly fine for me
https://github.com/nvim-neorg/neorg/assets/56943754/4b8ba668-977a-4128-89e7-0febbbcc0a68
@benlubas For binary file, {/ }
works fine, but sometimes explicit open with xdg-open
may be required, e.g., to open a .html
file, however it opens inside Neovim instead of a browser.
So it doesn't work the way you want for text files?
There's the inbuilt gx
command if you want to 'force' open a file externally, I think that it makes sense for neorg to open files that nvim can handle inside nvim, and only defer to xdg-open
when it sees a file that it can't handle.
FYI, the gx
command does not work for either {/ path/to/file}
or {file:path/to/file}
.
One issue is that gx doesn't seem to handle relative paths when the working directory is not the same as the directory containing the file. Let's say there is a file in ~/mydir/myfile.norg
and in that file we have
{/ ./index.html}
If the working directory is ~/mydir
, then gx
works fine. Otherwise though, if the working directory is some other directory than ~/mydir
, gx
will not open it, returning the error message vim.ui.open: command failed (2): { "xdg-open", "./index.html" }
.
It seems like there are a couple of approaches so that these links open in an external file:
{file:path/to/file}
links. There is a pull request (https://github.com/nvim-neorg/neorg/pull/1382) that I closed since {/ ./mypic.jpg}
works correctly. However, {/ path}
doesn't work for things that could be opened in either vim or an external file, the pull request would solve this issue.gx
so that it handles relative paths even when the working directory is not the same as the file.Personally it seems like the 2nd approach may be better since it would mean there is less link syntax to remember ({file:path}
wouldn't be needed) and users could decide themselves how to open links at read time (rather than it being forced at write time). In other words, opening in vim would be <cr>
and opening externally would be gx
.
Override gx so that it handles relative paths even when the working directory is not the same as the file.
I like this solution as well. Though I know that some people have custom implementations of this keybind already, so we have to make sure that we fallback to what's already there if it's used on something we don't handle. (for example many people add logic to make things that look like: nvim-neorg/neorg
open as a github link)
@pysan3 @vhyrro thoughts? I can handle the implementation (or @esquires if you would like to do it I'm not gonna stop you)
I just want mention, also, when the file name contains space, even for gx I have to have the file name selected, which is very not ergonomic.
@glyh with the addition of pathlib.nvim, you should be able to jump to a space-containing filepath with a simple <CR>
no problem. (Obviously neorg >= 0.8)
Could you describe your situation with more details?
When I want to open an HTML file with space in its name in an external browser. I have to select the whole file name and then use gx.
Even so, there's no way to open it in a new browser window. Chrome usually opens inside the same old browser window.
I kinda need this because I've experinced a lot when the web page is gone after some year and I would like to have a copy of it offline.
EDIT:
The second issue seems to be workaroundable with some wrapper on the external browser, but for the selection part there has to be some change in Neorg
Even so, there's no way to open it in a new browser window. Chrome usually opens inside the same old browser window.
this is not controlled by neorg
I kinda need this because I've experinced a lot when the web page is gone after some year and I would like to have a copy of it offline.
I don't see how this is related to neorg or anything else in this issue?
perhaps open a new issue if your problems aren't related to this issue (relative paths)
Yes I update that comment indicating that this might be workaroundable with wrappers.
Well it is related. I'm just explaining why I need this feature in case someone wonders.
Absolute path using {file:///abc}
can contain a space inside but relative path {/ abc}
can't if you just use gx
(you have to select it).
yes but what has the part about you wanting to use webpages offline todo with neorg?
I've already explained above this has nothing to do with this feature specifically, but why I need to have relative access to webpage (which is a use case). You are free to ignore them, I don't know why are you arguing with me on that point.
Discussed in https://github.com/nvim-neorg/neorg/discussions/456
The problem appears to be, that the File URI scheme does not (officially) support relative paths. However, we should be able to support some sensible custom solution for this within Neorg.