mirror of
https://github.com/Hopiu/lychee.git
synced 2026-05-18 02:31:06 +00:00
35 lines
963 B
Rust
35 lines
963 B
Rust
use crate::{utils::url, types::uri::raw::RawUri};
|
|
|
|
/// Extract unparsed URL strings from plaintext
|
|
pub(crate) fn extract_plaintext(input: &str) -> Vec<RawUri> {
|
|
url::find_links(input)
|
|
.map(|uri| RawUri::from(uri.as_str()))
|
|
.collect()
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_extract_local_links() {
|
|
let input = "http://127.0.0.1/ and http://127.0.0.1:8888/ are local links.";
|
|
let links: Vec<RawUri> = extract_plaintext(input);
|
|
assert_eq!(
|
|
links,
|
|
[
|
|
RawUri::from("http://127.0.0.1/"),
|
|
RawUri::from("http://127.0.0.1:8888/")
|
|
]
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_extract_link_at_end_of_line() {
|
|
let input = "https://www.apache.org/licenses/LICENSE-2.0\n";
|
|
let uri = RawUri::from(input.trim_end());
|
|
|
|
let uris: Vec<RawUri> = extract_plaintext(input);
|
|
assert_eq!(vec![uri], uris);
|
|
}
|
|
}
|