fix: resolve subfolder and relative wiki/md links - #495
Open
adsqx wants to merge 1 commit into
Open
Conversation
Normalize vault ref paths to `/` so Windows `\` from diff_paths matches links written with `/`. Resolve `./` and `../` links from the source note after the vault-root match, matching Obsidian. Fixes Feel-ix-343#274
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
/claim #274
Fixes #274
Fix "Unresolved Reference" for links to notes in subfolders (#274)
Two distinct bugs in
matches_path_or_filemade subfolder links resolve inconsistently:get_obsidian_ref_pathderives ref paths fromdiff_paths, which yields\on Windows, while links are written with/. The comparison was a raw string equality, so every path link failed on Windows. Ref paths are now normalized to/at the source (get_obsidian_ref_path), which also fixesRefname::link_file_key, previously splitting onMAIN_SEPARATOR; link text is normalized too, sosub\fileworks as well.current_dir/note.md,./sub_dir/filefailed while./current_dir/sub_dir/fileworked, because./was simply stripped. Path links are now matched against the vault root first (unchanged behavior), and, failing that, resolved against the directory of the note the link is written in, with.and..collapsed — so./fileand../othermean what they mean in Obsidian, and a link escaping the vault matches nothing.The Windows-only PRs (e.g. #493) fix (1) alone and leave every
./and../link unresolved on all platforms. This handles both, and keeps the existing bare-filename match to a file anywhere in the vault.The change is contained: two helpers plus the matcher, which now takes the path of the note the link is written in — both call sites (
Reference::references,Referenceable::matches_reference) already had it. Tests invault_testscover Windows separators in both directions,[[subfolder/file]]from root,./nested/fileand../other.mdfrom a subfolder note (and the negative cases), and a relative link to a heading.