Function parse_hyperlinks::parser::parse::take_text2dest_label2dest
source · pub fn take_text2dest_label2dest(
i: &str
) -> IResult<&str, (Cow<'_, str>, Cow<'_, str>, Cow<'_, str>)>
Expand description
Consumes the input until it finds a Markdown, RestructuredText, Asciidoc or
HTML formatted inline link (Text2Dest
) or link reference definition
(Label2Dest
).
Returns Ok((remaining_input, (link_text_or_label, link_destination, link_title)))
. The parser recognizes only stand alone inline links and
link reference definitions, but no reference links.
Limitations:
Link reference labels are never resolved into link text. This limitation only concerns this parser. Others are not affected.
Very often this limitation has no effect at all. This is the case, when the link text and the link label are identical:
abc [link text/label] abc
[link text/label]: /url "title"
But in general, the link text and the link label can be different:
abc [link text][link label] abc
[link label]: /url "title"
When a link reference definition is found, the parser outputs it’s link label instead of the link text, which is strictly speaking only correct when both are identical. Note, the same applies to RestructuredText’s link reference definitions too.
Another limitation is that ReStructuredText’s anonymous links are not supported.
Basic usage
use parse_hyperlinks::parser::parse::take_text2dest_label2dest;
use std::borrow::Cow;
let i = r#"[a]: b 'c'
.. _d: e
---[f](g 'h')---`i <j>`_---
---<a href="l" title="m">k</a>"#;
let (i, r) = take_text2dest_label2dest(i).unwrap();
assert_eq!(r, (Cow::from("a"), Cow::from("b"), Cow::from("c")));
let (i, r) = take_text2dest_label2dest(i).unwrap();
assert_eq!(r, (Cow::from("d"), Cow::from("e"), Cow::from("")));
let (i, r) = take_text2dest_label2dest(i).unwrap();
assert_eq!(r, (Cow::from("f"), Cow::from("g"), Cow::from("h")));
let (i, r) = take_text2dest_label2dest(i).unwrap();
assert_eq!(r, (Cow::from("i"), Cow::from("j"), Cow::from("")));
let (i, r) = take_text2dest_label2dest(i).unwrap();
assert_eq!(r, (Cow::from("k"), Cow::from("l"), Cow::from("m")));
The parser might silently consume some additional bytes after the actual finding: This happens,
when directly after a finding a md_link_ref
or rst_link_ref
appears. These must be ignored,
as they are only allowed at the beginning of a line. The skip has to happen at this moment, as
the next parser does not know if the first byte it gets, is it at the beginning of a line or
not.
Technically, this parser is a wrapper around take_link()
, that erases the
link type information and ignores all reference links. In case the input
text contains link reference definitions, this function is be faster than
the parse_hyperlinks::iterator::Hyperlink
iterator.
Note: This function is depreciated and will be removed in some later release.
Use take_link()
instead.