Fix body text loss on block-in-inline EPUB markup#427
Open
neoden wants to merge 1 commit into
Open
Conversation
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>
This was referenced Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_blocksin the HTML engine only checks direct children for block elements. Afterwrap_lost_inlineswraps the consecutive inline spans into an anonymous wrapper, the wrapper's children are all inline, so the engine takes the inline path andgather_inline_materialflattens 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_blockonElementData), 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