Function parse_hyperlinks::parser::markdown::md_text2label
source · pub fn md_text2label(i: &str) -> IResult<&str, (Cow<'_, str>, Cow<'_, str>)>
Expand description
Parse a Markdown reference link.
There are three kinds of reference links: full, collapsed, and shortcut.
- A full reference link consists of a link text immediately followed by a link label that matches a link reference definition elsewhere in the document.
- A collapsed reference link consists of a link label that matches a link
reference definition elsewhere in the document, followed by the string [].
The contents of the first link label are parsed as inlines, which are used as
the link’s text. The link’s URI and title are provided by the matching
reference link definition. Thus,
[foo][]
is equivalent to[foo][foo]
. - A shortcut reference link consists of a link label that matches a link
reference definition elsewhere in the document and is not followed by [] or a
link label. The contents of the first link label are parsed as inlines, which
are used as the link’s text. The link’s URI and title are provided by the
matching link reference definition. Thus,
[foo]
is equivalent to[foo][]
.
This parser expects to start at the beginning of the link [
to succeed.
It should always run at last position after all other parsers.
use parse_hyperlinks::parser::Link;
use parse_hyperlinks::parser::markdown::md_text2label;
use std::borrow::Cow;
assert_eq!(
md_text2label("[link text][link label]abc"),
Ok(("abc", (Cow::from("link text"), Cow::from("link label"))))
);
assert_eq!(
md_text2label("[link text][]abc"),
Ok(("abc", (Cow::from("link text"), Cow::from("link text"))))
);
assert_eq!(
md_text2label("[link text]abc"),
Ok(("abc", (Cow::from("link text"), Cow::from("link text"))))
);