Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion src/vault/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ impl Reference {
});

static MD_LINK_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"\[(?<display>[^\[\]\.]*?)\]\(<?(?<filepath>(\.?\/)?[^\[\]\|\.\#<>]+?)?(?<ending>\.[^\# <>]+?)?(\#(?<infileref>[^\[\]\.\|<>]+?))?>?\)")
Regex::new(r"\[(?<display>[^\[\]\.]*?)\]\(<?(?<filepath>(\.?\/)?[^\[\]\|\.\#<>()]+?)?(?<ending>\.[^\# <>]+?)?(\#(?<infileref>[^\[\]\.\|<>()]+?))?>?\)")
.expect("MD Link Not Constructing")
}); // [display](relativePath)

Expand Down Expand Up @@ -2013,6 +2013,51 @@ mod vault_tests {
assert_eq!(parsed, expected);
}

#[test]
fn md_empty_link_parsing() {
let text = "[]()";
let parsed = Reference::new(text, "test.md").collect_vec();

let expected = vec![Reference::MDFileLink(ReferenceData {
reference_text: "test.md".into(),
display_text: Some("".into()),
range: Range {
start: Position {
line: 0,
character: 0,
},
end: Position {
line: 0,
character: 4,
},
}
.into(),
})];

assert_eq!(parsed, expected);

let text = "[]()\n)";
let parsed = Reference::new(text, "test.md").collect_vec();

let expected = vec![Reference::MDFileLink(ReferenceData {
reference_text: "test.md".into(),
display_text: Some("".into()),
range: Range {
start: Position {
line: 0,
character: 0,
},
end: Position {
line: 0,
character: 4,
},
}
.into(),
})];

assert_eq!(parsed, expected);
}

#[test]
fn footnote_link_parsing() {
let text = "This is a footnote[^1]
Expand Down