Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Word never stores the list numbers you see — a DOCX converter has to run a numbering engine

A law firm sent me a 60-page contract to convert, and by section 7 every cross-reference was off by one. The text said "as set out in clause 6.3" while the heading it pointed to read "6.4". I assumed a typo in the source document — until the same drift showed up in three other files that week. The root cause changed how I think about Word documents: the numbers you see in a DOCX are not stored…

A law firm sent the reporter a 60-page contract to convert, but every cross-reference was off by one section. The text referenced clauses 6.3, 6.4, and so on, while the headings pointed to seemingly different sections. This discrepancy led the reporter to question the integrity of the document. After encountering the issue in three other files, the reporter realized that list numbers in DOCX files are not stored but computed at render time.

A numbered paragraph contains only the `w:numPr` with a `numId` and a nesting level. The visible number is generated by Word's numbering engine using the abstract numbering definition in the `numbering.xml`. This engine handles various formatting, start values, restart rules, and per-instance overrides. The reporter's first converter simply counted paragraphs and incremented digits, but this approach failed to account for legal formatting requirements like (a), (iv), or decimal-within-upper-level numbering.

To accurately render list numbers, the reporter implemented the sequence resolution rules from ECMA-376, including one counter per level, resetting deeper levels when a higher one increments, applying startOverride per numbering instance, and formatting every number through the level's pattern. This fix ensured that heading numbers matched Word's display exactly.

To verify the conversion process, the reporter used a regression test: converting the file, exporting the same file to PDF from Word, and diffing just the clause headings. Any drift indicated a bug in the conversion process. The key takeaway is that list numbers in DOCX are a virtual layer, computed rather than stored. If a converter renders lists as bullets or renumbers with its own logic, quoted clause references in the body text may point to the wrong clause.

The reporter now incorporates this numbering engine into their DOCX-to-Markdown API, ensuring that cross-references remain intact during conversion.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

A git tag is not a release: requests v2.16.1 declares 2.16.0

In psf/requests, the tag v2.16.1 points at code whose __version__.py says 2.16.0 . The tag v2.16.0 says the same, and the code differs between them.

  • Git tag v2.16.1 points to code version 2.16.0
  • Tag v2.16.0 also points to same code version
  • Discrepancy raises question of tags being different things

CERT: Beware of foreign Uni. scams on social media

The National Centre for Cyber Security has warned of a major fraud perpetrated, targeting those seeking to enter foreign universities.

  • CERT warns of foreign university scams on social media
  • Scammers use convincing information to defraud students and parents
  • Victims lose hundreds of thousands of rupees, receive no services

More from Saturday 10 October →