pub mod anchor;
pub mod cli;
pub mod config;
pub mod extractors;
pub mod ignore_link;
pub mod link;
pub mod markup;
pub mod result;
pub mod state;
use crate::anchor::Anchor;
use crate::link::Link;
pub use colored::*;
pub use config::Extractor as Config;
use git_version::git_version;
use state::State;
pub use wildmatch::WildMatch;
pub type BoxError = Box<dyn std::error::Error + Send + Sync>;
pub type BoxResult<T> = Result<T, BoxError>;
#[doc = include_str!("../README.md")]
#[cfg(doctest)]
pub struct ReadmeDoctests;
pub const VERSION: &str = git_version!(cargo_prefix = "", fallback = "unknown");
#[must_use]
pub async fn find_all_links(conf: &Config) -> (Vec<Link>, Vec<Anchor>, Vec<BoxError>) {
let mut links = vec![];
let mut anchor_targets = vec![];
let mut errors: Vec<_> = vec![];
for file in &conf.markup_files {
match markup::File::try_from(file.clone()) {
Ok(markup_file) => match extractors::gather_links(&markup_file, conf).await {
Ok(mut parsed) => {
links.append(&mut parsed.links);
anchor_targets.append(&mut parsed.anchors);
}
Err(err) => {
errors.push(err.into());
}
},
Err(err) => {
errors.push(err.into());
}
}
}
(links, anchor_targets, errors)
}
pub async fn run(state: &mut State) -> BoxResult<()> {
let (links, anchors, errors) = find_all_links(&state.config.extractor).await;
result::sink(&state.config, &links, &anchors, &errors)
.await
.map_err(Into::into)
}