Skip to main content

extract_vault_refs

Function extract_vault_refs 

Source
pub fn extract_vault_refs(text: &str) -> Vec<VaultRef>
Expand description

Every [[wikilink]] and ![[transclusion]] in already-flattened text, in document order. The alias is everything after the first |; the fragment is everything after the first # in what is left, so [[Note|alias#Part]] has the alias alias#Part and no fragment. The text between the brackets cannot contain [.

use markdown_contract::{VaultRefKind, extract_vault_refs};

let refs = extract_vault_refs("see [[Note#^id|the note]] and ![[Diagram]]");
assert_eq!(refs[0].target, "Note");
assert_eq!(refs[0].fragment.as_deref(), Some("^id"));
assert_eq!(refs[0].alias.as_deref(), Some("the note"));
assert_eq!(refs[1].kind, VaultRefKind::Transclusion);