fix(docx): preserve multi-level outline numbering from lvlText#3085
fix(docx): preserve multi-level outline numbering from lvlText#3085Br1an67 wants to merge 3 commits intodocling-project:mainfrom
Conversation
|
✅ 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
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
|
@Br1an67 Can you resolve the conflicts, would love to merge this in! |
|
@Br1an67 please see my comment on #2758 (comment) |
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: