pub fn parse_inner(inner: &str, embed: bool) -> Option<WikiLink>Expand description
Parse a single wikilink body (the text between the brackets).
A \ right before the first | is the escape a GFM table cell needs
([[Note\|alias]]) and is dropped from the target or heading.
ยงExamples
use markdown_link::{WikiLink, parse_inner};
let link = parse_inner("Note#Intro|Read me", false).unwrap();
assert_eq!(
link,
WikiLink {
target: "Note".into(),
heading: Some("Intro".into()),
block: None,
alias: Some("Read me".into()),
size: None,
embed: false,
}
);
// A `#^id` fragment is a block, not a heading.
let block = parse_inner("Note#^abc", false).unwrap();
assert_eq!((block.heading, block.block.as_deref()), (None, Some("abc")));
// An embed's trailing `|300` is its size; the alias keeps it as written.
let image = parse_inner("img.png|300", true).unwrap();
assert_eq!(image.size.map(|s| s.width), Some(300));
// The `\` that escapes the pipe in a table cell is dropped.
assert_eq!(parse_inner("Note\\|alias", false).unwrap().target, "Note");
// A link with no target is not a link.
assert!(parse_inner(" #only-heading", false).is_none());