Skip to content

fix: resolve subfolder and relative wiki/md links - #495

Open
adsqx wants to merge 1 commit into
Feel-ix-343:mainfrom
adsqx:fix/subfolder-relative-and-windows-links
Open

fix: resolve subfolder and relative wiki/md links#495
adsqx wants to merge 1 commit into
Feel-ix-343:mainfrom
adsqx:fix/subfolder-relative-and-windows-links

Conversation

@adsqx

@adsqx adsqx commented Aug 20, 2026

Copy link
Copy Markdown

/claim #274
Fixes #274

Fix "Unresolved Reference" for links to notes in subfolders (#274)

Two distinct bugs in matches_path_or_file made subfolder links resolve inconsistently:

  1. Separators. get_obsidian_ref_path derives ref paths from diff_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 fixes Refname::link_file_key, previously splitting on MAIN_SEPARATOR; link text is normalized too, so sub\file works as well.
  2. Relative links were resolved from the vault root, not from the note. This is the failure Huliiiiii reported in Helix: from current_dir/note.md, ./sub_dir/file failed while ./current_dir/sub_dir/file worked, 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 ./file and ../other mean 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 in vault_tests cover Windows separators in both directions, [[subfolder/file]] from root, ./nested/file and ../other.md from a subfolder note (and the negative cases), and a relative link to a heading.

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

Successfully merging this pull request may close these issues.

"Unresolved Reference" on .md files in subfolders

1 participant