fix: keep labels of auto-numbered DOCX lists

Merged
QU
1mo ago
+773-6

What

Word does not store the label of an auto-numbered list item (1., a), iv.) in the paragraph. It computes the label at render time from numbering.xml, so partition_docx() returned ListItem text with no label, while typed-in numbers were kept.

The label is now resolved and prefixed to the item text:

  • numId / ilvl come from the paragraph's w:numPr or its style chain (including basedOn), mapped through abstractNum with lvlOverride / startOverride.
  • Counters are kept per level in document order; a deeper level restarts when a shallower one advances, and a list continues counting after an intervening paragraph.
  • Labels follow numFmt (decimal, letters, roman numerals, ...) and lvlText (%1., %2), (%3), ...).
  • Bullets stay unprefixed. Missing or malformed numbering falls back to the previous text and never raises.
  • A paragraph that only inherits numbering from its style is now recognized as a list item, unless its style maps to another element type such as a heading.

This changes ListItem.text for every auto-numbered DOCX, so one existing expectation was updated to include the label.

🤖 Generated with Claude Code