pub fn adoc_text2label(i: &str) -> IResult<&str, (Cow<'_, str>, Cow<'_, str>)>
Expand description

Parse a Asciidoc reference link.

There are three kinds of reference links Text2Label: full, collapsed, and shortcut.

  1. A full reference link {label}[text] consists of a link label immediately followed by a link text. The label matches a link reference definition elsewhere in the document.
  2. A collapsed reference link {label}[] consists of a link label that matches a link reference definition elsewhere in the document, followed by the string []. In this case, the function returns an empty link text "", indicating, that the empty string must be replaced later by the link destination link_dest of the matching link reference definition (Label2Dest).
  3. 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 text [link text]. This is a shortcut of case 2. above.

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::asciidoc::adoc_text2label;
use std::borrow::Cow;

assert_eq!(
  adoc_text2label("{link-label}[link text]abc"),
  Ok(("abc", (Cow::from("link text"), Cow::from("link-label"))))
);
assert_eq!(
  adoc_text2label("{link-label}[]abc"),
  Ok(("abc", (Cow::from(""), Cow::from("link-label"))))
);
assert_eq!(
  adoc_text2label("{link-label}abc"),
  Ok(("abc", (Cow::from(""), Cow::from("link-label"))))
);