fix(twkan): wrap chapter text in paragraphs - #2979
Merged
dteviot merged 1 commit intoSep 12, 2026
Merged
Conversation
Owner
|
@KitKat31337 Thank you for your contribution |
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.
Summary
Convert TWKAN chapter content separated by
<br>elements into properly structured<p>elements before generating the EPUB.Problem
TWKAN provides chapter content as text nodes separated by
<br>elements:WebToEpub previously copied that structure directly, producing chapter documents similar to:
Most ebook readers display this correctly, but the chapter text exists directly under
<body>rather than inside text-containing elements.This causes problems for tools that process EPUB content structurally. In particular, the Calibre Ebook Translator plugin looks for translatable text inside elements. Because the TWKAN chapter text is stored as loose text nodes, the plugin detects the chapter headings but skips almost all of the actual book content.
Standards and interoperability
WebToEpub generates this content as EPUB 2 with an XHTML 1.1 doctype.
The XHTML 1.1 structure model defines the content model of
<body>as:Raw character data and inline
<br>elements are therefore not valid direct children of<body>under the declared XHTML 1.1 content model. Paragraphs are block elements and provide the appropriate structure for this content.The corrected output is:
Besides improving XHTML conformance, explicit paragraph markup makes the generated EPUB more interoperable with translation tools, accessibility software, converters, editors, and other applications that operate on document elements rather than loose text nodes.
Implementation
Add a TWKAN-specific
customRawDomToContentStep()that:<p>elements.<br>elements as paragraph boundaries and removes them afterward.<em>.The behavior is limited to
TwkanParserand does not affect EPUBs generated from other sites.Testing
Added a TWKAN parser unit test confirming that:
<br>elements are removed.The implementation was also tested against a real TWKAN chapter. It produced 87 paragraph elements while preserving all non-whitespace chapter text and leaving no loose body text or
<br>separators.