fix(docx): repair unindexed numbering definitions in docx preprocessor - #2457
Open
k3n (EtherK3N) wants to merge 1 commit into
Open
fix(docx): repair unindexed numbering definitions in docx preprocessor#2457k3n (EtherK3N) wants to merge 1 commit into
k3n (EtherK3N) wants to merge 1 commit into
Conversation
When converting DOCX files generated by tools such as Lark/Feishu or third-party exporters, multi-level lists lose their hierarchy because <w:lvl> elements omit w:ilvl attributes. While Mammoth attempts a fallback to "0", its internal dictionary only retains a single unindexed level per abstractNum, discarding subsequent sub-levels (1, 2, etc.). This adds _pre_process_numbering() to pre_process.py to assign sequential level indices (str(idx)) to unindexed <w:lvl> tags within each abstractNum before passing the document to Mammoth. Tested against sample files and added a unit test in test_module_vectors.py.
Author
|
@microsoft-github-policy-service agree |
San-Hsien (SanHsien)
added a commit
to SanHsien/markitdown
that referenced
this pull request
Sep 11, 2026
…ues with watermark microsoft#2457 and full-auto policy
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.
When converting DOCX files generated by certain tools (such as Lark/Feishu or third-party web exporters), multi-level lists lose their hierarchy or have sub-levels dropped.
Looking into the OOXML structure, these documents define
<w:lvl>elements inside<w:abstractNum>without explicitw:ilvlattributes. While Mammoth attempts a fallback to"0", its internal dictionary only retains a single unindexed level per abstract definition, overwriting and discarding any subsequent sub-levels (1, 2, etc.).This patch adds
_pre_process_numbering()topre_process.py, following the same approach already used in_pre_process_styles. It walksword/numbering.xmland assigns sequential indices (str(idx)) to any unindexed<w:lvl>tags before Mammoth parses the file. If all levels already carryw:ilvl(standard Word files) or if no numbering definitions exist, the content is returned untouched with no overhead.Tested against real-world sample files and added a unit test in
test_module_vectors.py. Formatting verified withblack.