embed-code-file icon indicating copy to clipboard operation
embed-code-file copied to clipboard

Allow relative paths

Open chintal opened this issue 3 years ago • 2 comments

Thanks for the great plugin. I'm using it with gregzuro/obsidian-kroki, and so far it seems to be working quite well.

It would be useful to be able to simply refer to files relative to the current file, though, instead of needing vault:// and effectively forcing absolute paths. I notice that you seem to have added this requirement quite recently.

I think the following heuristic may be more intuitive:

  • Paths starting with / or DriveLetter:/ are absolute paths for the local OS. Due to the nature of obsidian, one could make a case for not supporting such paths at all, to discourage embedding sources outside of the vault
  • Paths starting with scheme://, where scheme is one of [vault, http, https] continue to receive the current treatment as it is. This may be expanded later on to include other schemes, such as ftp, perhaps.
  • All other paths are treated as relative paths to the file the directives are found in.

For example, in the following folder structure, to reference test.py from Test.md for embedding, I would like to be able to use:

  • The relative path from the referencing file, PATH: "test.py" in Test.md
  • The absolute path within the vault, PATH: "vault://Notes/test.py"
  • The absolute path on the OS, PATH: "/home/someone/Vault/Notes/test.py"
VaultDir/
└── Notes
    ├── diagram.bpmn
    ├── Test.md
    └── test.py

chintal avatar Sep 10 '22 17:09 chintal

Hello @chintal,

actually the new vault:// requirement is similar to previous way. Obsidian reads paths using absolute path (within vault). So:

PATH: "Notes/test.py"

will read the file regardless the location of Test.md It is not possible to use:

PATH: "/Notes/test.py"

or (even if Test.md and test.py are in the same dir)

PATH: "test.py" 

Another way to implement the relative path (PATH: "test.py"), is to look to current mdFile stats (Test.md) and the fetch the current path appending it to the relative path.

For the third case PATH: "/home/someone/Vault/Notes/test.py" It is not possible to read files outside the vault working directory. I gave it a try and it is not working. Could be some security limits of running Obsidian.

Honestly I like something similar to links in Obsidian where you start tying [[ and then a nice menu with all links appears to select the file to be linked. I am still investigating how to implement something similar for PATH: ...

almariah avatar Sep 11 '22 14:09 almariah

@almariah There's any possibility to refer the directory which the file is contained? Like:

  • ./code_file.py if is in the same folder or,
  • ../other_folder/code_file.py if the file is in the a diferent directory.

see7e avatar Jun 02 '23 12:06 see7e