Skip to content

fix(docx): repair unindexed numbering definitions in docx preprocessor - #2457

Open
k3n (EtherK3N) wants to merge 1 commit into
microsoft:mainfrom
EtherK3N:fix/docx-numbering-missing-ilvl
Open

k3n (EtherK3N) wants to merge 1 commit into
microsoft:mainfrom
EtherK3N:fix/docx-numbering-missing-ilvl

Conversation

@EtherK3N

Copy link
Copy Markdown

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 explicit w:ilvl attributes. 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() to pre_process.py, following the same approach already used in _pre_process_styles. It walks word/numbering.xml and assigns sequential indices (str(idx)) to any unindexed <w:lvl> tags before Mammoth parses the file. If all levels already carry w: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 with black.

@EtherK3N

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

San-Hsien (SanHsien) added a commit to SanHsien/markitdown that referenced this pull request Sep 11, 2026
@EtherK3N
k3n (EtherK3N) force-pushed the fix/docx-numbering-missing-ilvl branch from fd5a7c6 to 016e8b4 Compare September 15, 2026 11:22
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_docx.py.
@EtherK3N
k3n (EtherK3N) force-pushed the fix/docx-numbering-missing-ilvl branch from 016e8b4 to 28dfb50 Compare October 15, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant