Fix: trim filenames while resolving wikilinks

Obsidian trims the filename part in a [[WikiLink|label]], so each of
these are equivalent:

[[wikilink]]
[[ wikilink ]]
[[ wikilink |wikilink]]

Obsidian-export now behaves similarly.

Fixes #188
This commit is contained in:
Nick Groenen 2023-12-02 12:19:16 +01:00
parent 4b88ad2b51
commit 151679788a
No known key found for this signature in database
GPG Key ID: 4F0AD019928AE098
3 changed files with 36 additions and 2 deletions

View File

@ -73,9 +73,9 @@ impl<'a> ObsidianNoteReference<'a> {
let captures = OBSIDIAN_NOTE_LINK_RE
.captures(text)
.expect("note link regex didn't match - bad input?");
let file = captures.name("file").map(|v| v.as_str());
let file = captures.name("file").map(|v| v.as_str().trim());
let label = captures.name("label").map(|v| v.as_str());
let section = captures.name("section").map(|v| v.as_str());
let section = captures.name("section").map(|v| v.as_str().trim());
ObsidianNoteReference {
file,

View File

@ -0,0 +1,17 @@
Obsidian trims space before and after the filename in a wikilink target.
These should all be the same:
[foo](foo.md)
[foo](foo.md)
[foo](foo.md)
[foo](foo.md)
[foo](foo.md)
[foo](foo.md)
[foo](foo.md)
[foo](foo.md)
[foo > ^abc](foo.md#abc)
[foo > ^abc](foo.md#abc)
[foo > ^abc](foo.md#abc)
[foo > ^abc](foo.md#abc)

View File

@ -0,0 +1,17 @@
Obsidian trims space before and after the filename in a wikilink target.
These should all be the same:
[[foo]]
[[ foo]]
[[foo ]]
[[ foo ]]
[[foo|foo]]
[[ foo|foo]]
[[foo |foo]]
[[ foo |foo]]
[[foo#^abc]]
[[foo#^abc ]]
[[foo#^abc |foo > ^abc]]
[[ foo#^abc ]]