Skip to content

Built-in EPUB engine drops body text on block-in-inline markup #426

Description

@neoden

Some EPUB converters emit invalid block-in-inline markup — block elements nested inside inline elements, often deeply:

<span><span id="...">
  <div class="title"></div>
  <div class="epigraph"></div>
  <p>body text…</p>
</span></span>

With such files the built-in reflowable engine renders only the chapter titles and epigraphs; all body paragraphs are silently dropped. (Reproducible with EPUBs produced by the royallib.com converter.)

Analysis: has_blocks in document/html/engine.rs only checks direct children for block elements. wrap_lost_inlines wraps the consecutive inline spans into an anonymous wrapper whose children are all inline, so the engine takes the inline path, and gather_inline_material flattens the nested <div>/<p> blocks into a single inline run — their content never produces lines.

Browsers handle this case by promoting the inline ancestors / splitting them around the blocks (CSS 2.1 §9.2.1.1), so the books display fine everywhere else, which makes the failure look like a Plato bug rather than a broken book.

I have a small self-contained fix (promote inline elements with block descendants to blocks before wrapping lost inlines) — PR incoming.

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