diff --git a/src/vault/mod.rs b/src/vault/mod.rs index 06ab07f4..3e2246b0 100644 --- a/src/vault/mod.rs +++ b/src/vault/mod.rs @@ -744,7 +744,7 @@ impl Reference { }); static MD_LINK_RE: Lazy = Lazy::new(|| { - Regex::new(r"\[(?[^\[\]\.]*?)\]\((\.?\/)?[^\[\]\|\.\#<>]+?)?(?\.[^\# <>]+?)?(\#(?[^\[\]\.\|<>]+?))?>?\)") + Regex::new(r"\[(?[^\[\]\.]*?)\]\((\.?\/)?[^\[\]\|\.\#<>()]+?)?(?\.[^\# <>]+?)?(\#(?[^\[\]\.\|<>()]+?))?>?\)") .expect("MD Link Not Constructing") }); // [display](relativePath) @@ -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]