//! HTML documents (feature `flow`): the HTML parts of WordCraft's cross-format and MathML tests
//! (`crates/formats/src/tests.rs`, `mathml.rs`): equations through HTML, hostile input, entities.
use craft_flow::{FBlock, Inline};
use craft_html::doc::{import, inlines_html, parse};
use std::time::{Duration, Instant};
fn equations(html: &str) -> Vec<(String, bool)> {
let mut out = Vec::new();
for b in &parse(html).blocks {
if let FBlock::Para(p) = b {
for i in &p.inlines {
if let Inline::Equation { linear, display } = i {
out.push((linear.clone(), *display));
}
}
}
}
out
}
#[test]
fn html_export_round_trips_equations() {
for (linear, display) in [("y=2x_s", false), ("x=(-b±√(b^2-4ac))/2a", true), ("∑_(k=1)^n▒k", false), ("■(a&b@c&d)", false)] {
let html = inlines_html(&[Inline::Equation { linear: linear.into(), display }]);
assert!(html.starts_with("
")), vec![(linear.to_string(), display)], "{html}");
}
// Text after the equation still arrives; an unclosed element ends with the input.
assert!(import(" tail
").plain_text(Default::default()).contains("tail"));
assert!(!equations("