Skip to content

Page-level classifier: content / chapter_opener / special_page / picture #33

Description

@Arkoniak

Background

build_html.py currently treats all non-picture pages as stitchable content and renders them as <p> paragraphs. This is wrong for:

  • Epigraph / front-matter pages (short isolated quote, e.g. page 8 "Law stops at atmosphere") — should be <section epub:type="epigraph"> or <blockquote>, NOT stitched to neighbours
  • Chapter openers — should trigger a new EPUB chapter, NOT stitch with the preceding page (this mostly works via the heading label already, but needs to be made explicit)
  • Picture pages — currently skipped entirely; should emit <figure><img> (see Image extraction from PDF: extract_images.py for picture-page embedding #34)

Brainstorm: docs/brainstorm.md § "Page-level classification for HTML assembly (design 2026-06-29)".

Page classes

Class Detection HTML output Stitching
content default <p> yes
chapter_opener first token block label = title/heading <h1>/<h2> + <p> no (starts new chapter)
special_page total_tokens < 40 AND no title/heading AND not picture <blockquote> / <section epub:type="epigraph"> no
picture picture_page=True <figure><img src="images/page_NNN.jpg"/></figure> no

Plan

  1. Add classify_page(page_result) -> str function in build_html.py — pure heuristic, no model needed, operates on voted_tokens + picture_page flag already in consensus output.
  2. Update build_book_html() to call it per page and route to the appropriate renderer.
  3. Picture pages: emit <figure><img> (requires images to be extracted, see Image extraction from PDF: extract_images.py for picture-page embedding #34).
  4. Special pages: emit <blockquote> with no stitching on either boundary.
  5. Chapter openers: block stitching with preceding page (already works via stitch_boundary label check, but make it explicit via page class).

Depends on

Acceptance criteria

  • classify_page() function with tests covering all four classes
  • Epigraph page 8 ("Law stops at atmosphere") renders as <blockquote> in book.html
  • Picture pages emit <figure><img> pointing to extracted images
  • No regression on stitching stats (word_split / paragraph_continuation counts unchanged)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions