fix: preserve DOCX heading numbering - #5270
Open
lvhua6352 wants to merge 1 commit into
Open
Conversation
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
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.
Motivation
DOCX heading outline levels and Word numbering levels represent different concepts.
For example, a paragraph can have:
outlineLvl=1, meaning it is a semantic level-2 heading and should render as##.numId=3,ilvl=0, andlvlText=%1., meaning it uses the first numbering level and should display1.,2., etc.Previously, the DOCX converter only preserved the semantic heading level. The middle-JSON conversion then reconstructed the section number from

level=2, incorrectly producing1.1,1.2, etc.This PR preserves the heading level while deriving the displayed section number from the actual Word numbering definition.
Modification
section_numberfor numbered DOCXHeadingblocks.numIdandilvlfromword/numbering.xml.%1to%9placeholders fromlvlTextwhile preserving punctuation.section_numberthrough the OfficeMagicModel.section_numberduring middle-JSON conversion.section_number.BC-breaking (Optional)
No backward-incompatible changes are introduced.
section_numberwas already used by the Office middle-JSON and Markdown rendering code. This PR only provides the existing field earlier in the DOCX conversion pipeline and preserves it throughMagicModel.Inputs without an explicit
section_numbercontinue to use the existing level-based numbering fallback. The additional field in DOCX model output is additive and does not change the existing public API.Use cases (Optional)
This fixes automatically numbered DOCX headings whose semantic outline level differs from their numbering level.
Example:
outlineLvl=1→ Markdown##ilvl=0,lvlText=%1.→1.,2.Before:
## 1.1 Virtual heading A## 1.2 Virtual heading BAfter:
## 1. Virtual heading A## 2. Virtual heading BChecklist
Before PR:
After PR: