[−][src]Function parse_hyperlinks::parser::take_hyperlink
pub fn take_hyperlink(i: &str) -> IResult<&str, (String, String, String)>
Consumes the input until it finds a Markdown or RestructuredText hyperlink. Returns
Ok(remaining_input, (link_name, link_target, link_title)
. The parser finds stand alone links
and link references. ReStructuredText's anonymous links are not supported.
use parse_hyperlinks::parser::take_hyperlink; let i = "[a]: b 'c'\n.. _d: e\n--[f](g 'h')--`i <j>`_--"; let (i, r) = take_hyperlink(i).unwrap(); assert_eq!(r, ("a".to_string(),"b".to_string(),"c".to_string())); let (i, r) = take_hyperlink(i).unwrap(); assert_eq!(r, ("d".to_string(),"e".to_string(),"".to_string())); let (i, r) = take_hyperlink(i).unwrap(); assert_eq!(r, ("f".to_string(),"g".to_string(),"h".to_string())); let (i, r) = take_hyperlink(i).unwrap(); assert_eq!(r, ("i".to_string(),"j".to_string(),"".to_string()));
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.