pub struct Linkifier { /* private fields */ }Expand description
A link detector over one scheme list.
Implementations§
Source§impl Linkifier
impl Linkifier
Sourcepub fn new<S: AsRef<str>>(schemes: impl IntoIterator<Item = S>) -> Linkifier
pub fn new<S: AsRef<str>>(schemes: impl IntoIterator<Item = S>) -> Linkifier
A detector for exactly these scheme prefixes ("https://",
"mailto:"). Matching is case-insensitive; empty entries are
ignored, and so is an entry without a :, which could never be
a scheme.
Sourcepub fn allows(&self, href: &str) -> bool
pub fn allows(&self, href: &str) -> bool
Whether href starts with one of the schemes. What a markdown
[label](url) is checked against: anything else — javascript:,
data:, file: — renders as the literal text that was typed.
Sourcepub fn has_scheme(&self, word: &str) -> bool
pub fn has_scheme(&self, word: &str) -> bool
Whether a word starts with a scheme or a bare www.-style prefix.
Sourcepub fn is_url(&self, word: &str) -> bool
pub fn is_url(&self, word: &str) -> bool
Whether a whitespace-delimited word is a link: a URL, or a bare email address.
Sourcepub fn normalize(&self, word: &str) -> String
pub fn normalize(&self, word: &str) -> String
The form of word a launcher can open: a scheme is prepended to
bare www. hosts and email addresses, and anything already
carrying one comes back unchanged.
Sourcepub fn scan(&self, text: &str) -> Vec<Range<usize>>
pub fn scan(&self, text: &str) -> Vec<Range<usize>>
Every link in text, as byte ranges on character boundaries.
A link starts at the beginning of the text or after whitespace or
an opening delimiter, and runs to whitespace or a closing one.
Trailing sentence punctuation is dropped, and so is a closing
paren or bracket — unless the URL opened one itself, which is the
shape of a Wikipedia link. Bare email addresses are links too,
which Linkifier::normalize turns into mailto:.