fix(pdf): use extracted markdown when ImageBased pages yield text

DR
11h ago
+107-6

Summary

An image-heavy PDF page with a short text caption can be classified as ImageBased. The fallback extraction finds the caption, but to_markdown discards it and returns an unsupported error.

When the initial Markdown is missing or blank and no flagged pages still need OCR, to_markdown now uses the extracted text. If only some pages were flagged, it extracts all pages so text from unflagged pages is preserved. Image-only pages still return NeedsOcr.

Fixes #230.

Test Plan

  • Added regression tests for an image-only page and an image with a short caption.
  • cargo +stable test --lib: 288 passed.
  • cargo +stable clippy --lib -- -D warnings: passed.
  • cargo +stable fmt --check: passed.

Summary by cubic

Fixes PDFs with image-heavy pages and short text captions incorrectly failing with NeedsOcr. When the initial markdown is blank and fallback extraction yields text from flagged pages, to_markdown now returns that text instead of an error.

  • Image-only pages still return NeedsOcr.
  • When only some pages are flagged, to_markdown extracts all pages in one pass, verifying OCR needs for every flagged page while preserving text from unflagged pages.

Fixes #230.