mod report;
pub use report::ConversionReport;
use kopitiam_pdf::Page;
use crate::{Block, Document};
pub fn validate(pages: &[Page], document: &Document, rendered_markdown: &str) -> ConversionReport {
let extracted_words = pages
.iter()
.flat_map(|page| &page.spans)
.map(|span| word_count(&span.text))
.sum();
let mut headings_found = 0;
let mut lists_found = 0;
let mut tables_found = 0;
for block in &document.blocks {
match block {
Block::Heading(_) => headings_found += 1,
Block::List(_) => lists_found += 1,
Block::Table(_) => tables_found += 1,
_ => {}
}
}
ConversionReport {
pages: pages.len(),
extracted_words,
rendered_words: word_count(rendered_markdown),
headings_found,
lists_found,
tables_found,
citations_found: document.citations.len(),
}
}
fn word_count(text: &str) -> usize {
text.split_whitespace().count()
}