Skip to content

fix(docx): resolve linked style numbering - #4727

Merged
PeterStaar-IBM merged 4 commits into
docling-project:mainfrom
LubabaKhalid:fix/docx-num-style-link-numbering
Oct 13, 2026
Merged

PeterStaar-IBM merged 4 commits into
docling-project:mainfrom
LubabaKhalid:fix/docx-num-style-link-numbering

Conversation

@LubabaKhalid

Copy link
Copy Markdown
Contributor

Summary

Fix DOCX heading numbering when numbering definitions use w:numStyleLink to reference a linked list style.

  • Follow w:numStyleLink to resolve numbering levels from the linked paragraph style.
  • Synchronize numbered heading counters with list counters so custom numbering templates such as Tabell %1.%7 use the correct chapter number.
  • Render custom-numbered table captions as paragraph text instead of unmarked list items.
  • Add regression tests for linked numbering styles, heading counter synchronization, and caption numbering.

Issue resolved by this Pull Request:

Resolves #4599

Checklist

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

Review evidence

Before: Headings numbered through a linked list style lost their numbers. Custom-numbered table captions could also lose their numbering and be exported as Markdown list items.

After: The reported Prop. 39 L document produces the expected headings:

  • 2 Gjeldende rett
  • 2.1 Nemndas klagesaksbehandling
  • 2.2 Søksmål om nemndas vedtak

The reported Prop. 34 L document produces the expected Tabell 14.1 Saker som kan rettsmekles... caption without an unwanted Markdown list bullet.

Checks performed:

  • ruff check on the modified backend and test files — passed.
  • pytest -q tests/test_backend_msword.py tests/test_backend_msword_lists.py — 269 passed, 1 skipped.
  • git diff --check — passed.

The regression tests cover linked numbering-style resolution, heading/list-counter synchronization, and custom caption numbering.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @LubabaKhalid, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working docx issue related to docx backend layout labels Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit 6c125d73fa. The analysis read the diff only. It did not run code from this pull request.

The PR makes the DOCX backend follow `w:numStyleLink` when it looks up numbering levels. It also syncs heading counters with list counters, and it writes custom-numbered captions as paragraph text instead of list items.

CI safety: no concern found. A maintainer must still approve CI.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

Signed-off-by: Lubaba Khalid <129605617+LubabaKhalid@users.noreply.github.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): changes are suggested

This review covers the full diff at a4604e656e. It read the code only. It did not run tests or code from this pull request.

This pull request resolves DOCX heading numbering definitions that reference linked list styles through w:numStyleLink, synchronizes heading counters with list templates, and renders numbered captions as paragraph text. The main risks are cross-chapter caption counter accumulation due to missing subordinate counter resets and accidental inclusion of unrelated layout postprocessor changes from PR #4704.

A maintainer makes the merge decision. This review never approves the pull request.

Comment thread docling/utils/layout_postprocessor.py Outdated
Comment thread docling/backend/msword_backend.py
Comment thread docling/backend/msword_backend.py
Comment thread tests/test_backend_msword.py
@github-actions github-actions Bot added the ai:review-changes AI first review suggests changes label Oct 9, 2026
@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.52632% with 28 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/msword_backend.py 70.52% 13 Missing and 15 partials ⚠️

📢 Thoughts on this report? Let us know!

@LubabaKhalid
LubabaKhalid force-pushed the fix/docx-num-style-link-numbering branch from a4604e6 to bde71bd Compare October 9, 2026 12:57
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-changes AI first review suggests changes labels Oct 9, 2026
PeterStaar-IBM
PeterStaar-IBM previously approved these changes Oct 10, 2026

@PeterStaar-IBM PeterStaar-IBM left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@morten-lagabote

Copy link
Copy Markdown
Contributor

I checked the head (bde71bd) against the two documents of #4599:

  • Prop. 39 L (2022–2023): 14 of 14 headings have their number (1 to 5, no gap in the sequence).
  • Prop. 34 L (2022–2023): 174 of 174 headings have their number (1 to 15.4, no gap in the sequence). The 7 table titles are Tabell 14.1 to Tabell 14.7, as text items.

No other line of the Markdown export changes. One limit: all 7 tables are in chapter 14, so these documents do not test the table counter in a new chapter.

@LubabaKhalid

Copy link
Copy Markdown
Contributor Author

I checked the head (bde71bd) against the two documents of #4599:

  • Prop. 39 L (2022–2023): 14 of 14 headings have their number (1 to 5, no gap in the sequence).
  • Prop. 34 L (2022–2023): 174 of 174 headings have their number (1 to 15.4, no gap in the sequence). The 7 table titles are Tabell 14.1 to Tabell 14.7, as text items.

No other line of the Markdown export changes. One limit: all 7 tables are in chapter 14, so these documents do not test the table counter in a new chapter.

Thanks for testing both documents and confirming the heading numbering and unchanged Markdown output! Good point about the table counter across chapters. I'll look into adding coverage for that case.

Signed-off-by: Lubaba Khalid <129605617+LubabaKhalid@users.noreply.github.com>
@LubabaKhalid
LubabaKhalid force-pushed the fix/docx-num-style-link-numbering branch from 3cdd324 to 2391415 Compare October 11, 2026 17:04
…s.noreply.github.com>

I, Lubaba Khalid <129605617+LubabaKhalid@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 70ca33f

Signed-off-by: Lubaba Khalid <129605617+LubabaKhalid@users.noreply.github.com>
@LubabaKhalid

Copy link
Copy Markdown
Contributor Author

I checked the head (bde71bd) against the two documents of #4599:

  • Prop. 39 L (2022–2023): 14 of 14 headings have their number (1 to 5, no gap in the sequence).
  • Prop. 34 L (2022–2023): 174 of 174 headings have their number (1 to 15.4, no gap in the sequence). The 7 table titles are Tabell 14.1 to Tabell 14.7, as text items.

No other line of the Markdown export changes. One limit: all 7 tables are in chapter 14, so these documents do not test the table counter in a new chapter.

Thanks for pointing out the cross-chapter counter gap! I've added regression coverage to verify that caption numbering restarts at Tabell 3.1 when a new chapter begins, while unrelated list counters retain their values. The focused MS Word backend tests pass locally (269 passed, 1 skipped). I've also addressed the formatting check and am updating the PR with these changes.

@morten-lagabote

Copy link
Copy Markdown
Contributor

The new head (6c125d7) gives the same result on both documents.

@LubabaKhalid

Copy link
Copy Markdown
Contributor Author

@PeterStaar-IBM Could you please review this PR?

@PeterStaar-IBM PeterStaar-IBM left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@PeterStaar-IBM
PeterStaar-IBM merged commit ffce191 into docling-project:main Oct 13, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working docx issue related to docx backend layout

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOCX: headings numbered through a linked list style (w:numStyleLink) lose their numbers

4 participants