feat: add EPUB book Markdown serializer - #720
Open
salmonumbrella wants to merge 2 commits into
Open
Conversation
Serialize a DoclingDocument as Markdown preceded by a YAML frontmatter block holding the book metadata and a chapter index. Each chapter entry carries the absolute UTF-8 byte offset and the 1-based line number of its heading, so a reader can seek straight to a chapter instead of scanning the whole book. The offsets are advertised inside the block they measure, so the frontmatter is rendered twice: once to measure how far it shifts the body, and once with the shifted offsets. Padding every offset to a fixed width keeps the two renderings the same size. A chapter is a top-level part opening on a TitleItem or a level-1 SectionHeaderItem, because an EPUB spine document may title its chapters with either <h1> or <h2>. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: salmonumbrella <182032677+salmonumbrella@users.noreply.github.com>
Contributor
|
✅ DCO Check Passed Thanks @salmonumbrella, all your commits are properly signed off. 🎉 |
Contributor
Merge Protections🔴 1 of 2 protections blocking · waiting on 👀 reviews
🔴 Require two reviewer for test updatesWaiting for
This rule is failing.When test data is updated, we require two reviewers
Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
salmonumbrella
added a commit
to salmonumbrella/docling
that referenced
this pull request
Aug 14, 2026
… format Address review feedback on docling-project#3993: - Drop docling/backend/epub_serializer.py. The serializer now lives in docling-core as EpubDocSerializer, reached through the new DoclingDocument.export_to_epub() / save_as_epub() shorthands (docling-project/docling-core#720). - Replace the --md-book-frontmatter and --md-chapter-index flags with a standalone `epub` output format, written as <name>.epub.md. The CLI turns on rewrite_internal_links automatically when it is requested. - Drop the EpubDocument subclass of DoclingDocument. The OPF package metadata is transient backend state, so it rides on ConversionResult._epub_metadata, the same private-attr plumbing already used for _pdf_outline. The serializer tests moved to docling-core alongside the code; what remains here covers the backend, the plumbing, and the CLI format. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: salmonumbrella <182032677+salmonumbrella@users.noreply.github.com>
3 tasks
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Signed-off-by: salmonumbrella <182032677+salmonumbrella@users.noreply.github.com>
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.
What changed
Adds
EpubDocSerializer, aMarkdownDocSerializervariant that renders a book as Markdown preceded by a YAML frontmatter block holding the book metadata and a chapter index, plusDoclingDocument.export_to_epub()/save_as_epub().Every chapter entry carries the absolute UTF-8 byte offset and the 1-based line number of its heading, so a reader can seek straight to a chapter instead of unpacking the source or scanning the whole book.
Why
Requested by @dolfim-ibm in review of docling-project/docling#3993, which had the same serializer living in
docling/backend/epub_serializer.py:The companion docling PR is being restructured to drop its local serializer and consume this one behind a new
epuboutput format.Notes for reviewers
Two details are load-bearing and have dedicated tests:
TitleItemor a level-1SectionHeaderItem. An EPUB spine document may title its chapters with either<h1>or<h2>, and the HTML backend maps<h1>to a title item. Matching only section headers leaves the index empty for every book that uses<h1>per chapter.save_as_epub()writes raw UTF-8 bytes rather than going through text mode, since the advertised offsets index the saved file and Windows newline translation would invalidate them.Checklist
test/test_epub_serialization.py, 9 cases)pytest test— 606 passed, 6 skippedruff check/ruff format/mypyclean🤖 Generated with Claude Code