pub mod bail;
pub mod parse;
pub mod router;
pub mod scanner;
pub mod spec_rules;
pub mod state;
pub mod tags;
pub use tags::lookup;
#[cfg(any(test, feature = "testkit"))]
pub use bail::BailReason;
#[cfg(any(test, feature = "testkit"))]
pub use tags::{ListKind, OptionalCloseRule, RawKind, TagKind, TagSpec};
pub use router::RouterDecision;
use crate::converter::prescan::PrescanReport;
use crate::options::ConversionOptions;
pub fn run(html: &str, report: &PrescanReport, options: &ConversionOptions) -> Result<String, bail::BailReason> {
let document_base_href = options
.extract_metadata
.then(|| crate::converter::url_resolve::document_base_href(html))
.flatten();
run_with_base(html, report, options, None, document_base_href.as_deref())
}
pub fn run_with_base(
html: &str,
report: &PrescanReport,
options: &ConversionOptions,
effective_base: Option<std::rc::Rc<url::Url>>,
document_base_href: Option<&str>,
) -> Result<String, bail::BailReason> {
run_with_policy(
html,
report,
options,
effective_base,
document_base_href,
Default::default(),
)
}
pub(crate) fn run_with_policy(
html: &str,
_report: &PrescanReport,
options: &ConversionOptions,
effective_base: Option<std::rc::Rc<url::Url>>,
document_base_href: Option<&str>,
policy: crate::convert_api::AccessibleNamePolicy,
) -> Result<String, bail::BailReason> {
if !options.exclude_selectors.is_empty() {
return Err(bail::BailReason::Classifier);
}
let scanner::ScanOutput { body, .. } = scanner::scan_with_policy(html, options, effective_base, policy)?;
if let Some(frontmatter) = crate::converter::head_metadata::extract_frontmatter(html, options, document_base_href) {
let mut output = String::with_capacity(frontmatter.len() + body.len() + 1);
output.push_str(&frontmatter);
if !body.is_empty() && !body.starts_with('\n') && !frontmatter.ends_with("\n\n") {
output.push('\n');
}
output.push_str(&body);
return Ok(output);
}
Ok(body)
}
#[cfg(test)]
mod accessible_name_tests {
use super::*;
#[test]
fn should_apply_explicit_svg_policy_without_tier2_fallback() {
let html = r#"<svg aria-label="Name"><title>Tooltip</title><text>Drawn</text></svg>"#;
for (enabled, caption) in [(true, "![Name Tooltip Drawn"), (false, "![Drawn")] {
let output = run_with_policy(
html,
&PrescanReport::default(),
&ConversionOptions::default(),
None,
None,
crate::convert_api::AccessibleNamePolicy(enabled),
)
.expect("the scanner must finish without falling back");
assert_eq!(output.split_once("](data:image/svg+xml;base64,").unwrap().0, caption);
}
}
}