Skip to content

Fix body text loss on block-in-inline EPUB markup#427

Open
neoden wants to merge 1 commit into
baskerville:masterfrom
neoden:fix/epub-block-in-inline
Open

Fix body text loss on block-in-inline EPUB markup#427
neoden wants to merge 1 commit into
baskerville:masterfrom
neoden:fix/epub-block-in-inline

Conversation

@neoden

@neoden neoden commented Jun 12, 2026

Copy link
Copy Markdown

Fixes #426.

Some EPUB converters emit invalid block-in-inline markup, e.g.
<span><span id><div class="title">…</div><div class="epigraph">…</div><p>body</p></span></span>.

With such files the built-in reflowable engine renders only chapter titles and epigraphs — the body paragraphs vanish.

Root cause: has_blocks in the HTML engine only checks direct children for block elements. After wrap_lost_inlines wraps the consecutive inline spans into an anonymous wrapper, the wrapper's 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, dropping their content.

Fix: before wrapping lost inlines, promote any inline element that has a block-level descendant to a block (force_block on ElementData), so it's laid out normally instead of being flattened. This approximates the CSS 2.1 §9.2.1.1 behaviour (browsers split inline boxes around in-flow blocks), which is why these books display correctly everywhere else.

Verified on the emulator and on a Kobo Clara BW: affected books render all body text; justification, reader settings and TOC keep working.

🤖 Generated with Claude Code

Some EPUB converters produce invalid block-in-inline markup, e.g.
<span><div class="title">…</div><p>…</p></span>. The engine only
checks direct children for blocks, so once wrap_lost_inlines wraps
such spans, gather_inline_material flattens the nested blocks into
a single inline run and the body text vanishes.

Promote any inline element that has a block-level descendant to a
block before wrapping lost inlines, so its content is laid out
normally.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant