fix(docx): preserve multi-level outline numbering from lvlText#3085
Open
Br1an67 wants to merge 3 commits intodocling-project:mainfrom
Open
fix(docx): preserve multi-level outline numbering from lvlText#3085Br1an67 wants to merge 3 commits intodocling-project:mainfrom
Br1an67 wants to merge 3 commits intodocling-project:mainfrom
Conversation
Contributor
|
✅ DCO Check Passed Thanks @Br1an67, all your commits are properly signed off. 🎉 |
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
3612ac2 to
59ebfb9
Compare
3 tasks
Fixed a bug where multi-level outline numbering (e.g., "3.1", "3.2") was rendered as single-level only (e.g., "1", "2", "3"), losing the hierarchical structure. Changes: - Added _get_level_element() to extract level elements from numbering XML - Refactored _is_numbered_list() to use the new helper function - Added _get_level_text() to read the w:lvlText format string (e.g., "%1.%2") - Added _build_multi_level_marker() to construct multi-level markers by substituting placeholders (%1, %2, etc.) with actual counter values - Updated all marker generation in _add_list_item() to use the new function The fix properly handles Word's outline numbering format strings, which define how multi-level numbers should be constructed (e.g., "%1.%2" produces "3.1"). Signed-off-by: Br1an67 <932039080@qq.com>
- Replace Optional[X] with X | None for type annotations - Remove unused Optional import from typing - Apply ruff formatting This resolves the UP045 lint errors in code-checks / lint (3.12) Signed-off-by: Br1an67 <932039080@qq.com>
- Import Callable from collections.abc instead of typing (UP035) - Replace Union[X, Y] with X | Y for type annotations (UP007) - Remove unused Union import from typing - Apply ruff formatting This resolves the remaining UP lint errors in code-checks / lint (3.12) Signed-off-by: Br1an67 <932039080@qq.com>
3f5d1da to
292d0b5
Compare
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.
Issue resolved by this Pull Request:
Resolves #2758
Summary
Fixed a bug where multi-level outline numbering in DOCX documents (e.g., "3.1", "3.2") was being rendered as single-level only (e.g., "1", "2", "3"), losing the hierarchical structure.
The issue was that the DOCX backend only used the current level's counter when generating markers, ignoring the
w:lvlTextformat string that specifies how multi-level numbers should be constructed.Changes
_get_level_element()helper to extract level elements from numbering XML, reducing code duplication_is_numbered_list()to use the new helper function_get_level_text()to read thew:lvlTextformat string from DOCX numbering definitions (e.g., "%1.%2")_build_multi_level_marker()to construct multi-level markers by substituting placeholders (%1, %2, etc.) with actual counter values from parent levels_add_list_item()to use the new multi-level marker builderTechnical Details
Word's outline numbering uses
w:lvlTextelements to define the format of multi-level numbers:%1= level 0 counter%2= level 1 counter%1.%2produces "3.1" (parent counter + dot + current counter)%1.%2.%3produces "3.2.1" for three-level numberingThe fix properly reads these format strings and substitutes the placeholders with the appropriate counter values from all relevant levels.
Testing
The fix handles:
Diff Stats
Checklist: