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:
parent
4b88ad2b51
commit
151679788a
@ -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,
|
||||
|
17
tests/testdata/expected/main-samples/issue-188-wikilinks-need-trimming.md
vendored
Normal file
17
tests/testdata/expected/main-samples/issue-188-wikilinks-need-trimming.md
vendored
Normal 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)
|
17
tests/testdata/input/main-samples/issue-188-wikilinks-need-trimming.md
vendored
Normal file
17
tests/testdata/input/main-samples/issue-188-wikilinks-need-trimming.md
vendored
Normal 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 ]]
|
Loading…
Reference in New Issue
Block a user