Fix EPUB conversion with namespace prefixes - #2480
Open
Gali (Jokasa7) wants to merge 1 commit into
Open
Conversation
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.
EPUB conversion currently depends on XML prefix spelling. With
ocf:rootfileincontainer.xml, conversion raisesIndexError(wrapped inFileConversionExceptionbyMarkItDown.convert_stream). With prefixedopf:item/opf:itemref, conversion succeeds but silently omits every chapter. Binding Dublin Core to a different prefix drops the book metadata.Match structural elements by their namespace URI and local name, retaining compatibility with unqualified structural elements. Match Dublin Core metadata by its URI while preserving the existing text helpers. Elements in unrelated namespaces cannot replace a rootfile, override a manifest entry, duplicate a chapter, or supply book metadata.
The EPUB specification defines the OCF and package namespaces, and XML Namespaces permits equivalent namespace prefixes. This change is separate from #1728, which addresses relative paths and prefixes inside chapter XHTML. Chapter HTML conversion and href resolution are unchanged here.
Validation:
MarkItDown.convert_stream, independent OCF/OPF/DC aliases, default-namespace Dublin Core, multiple authors, reversed spine order, foreign-namespace collisions, and legacy unqualified structural elements.pre-commit run --all-files: passed.hatch teston Windows / Python 3.12: 912 passed, 5 skipped, 1 failed. The only failure is the existing speech-transcription test becauseffprobeis not installed (AudioConverterraisesFileNotFoundError). The same test fails identically when importing an untouchedgit archive HEADcopy of all runtime sources in the same Hatch environment. No tests were disabled or modified to suppress it.The tests build minimal in-memory EPUB fixtures; they do not claim EPUBCheck validation of a complete publication. The fix and tests were generated and independently reviewed with Codex. Validation uses real ZIP/XML/HTML conversion without model services.