Skip to content

fix(odf): keep the text of a table of contents - #4750

Open
ryanmeowy wants to merge 2 commits into
docling-project:mainfrom
ryanmeowy:fix/odt-table-of-content
Open

ryanmeowy wants to merge 2 commits into
docling-project:mainfrom
ryanmeowy:fix/odt-table-of-content

Conversation

@ryanmeowy

@ryanmeowy ryanmeowy commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Issue resolved by this Pull Request:
Resolves #4749

Checklist:

  • Documentation has been updated, if necessary. (Not needed. The reader is internal.)
  • Examples have been added, if necessary. (Not needed.)
  • Tests have been added, if necessary. tests/test_backend_opendocument.py builds an ODT for a table of contents and for each other index kind, and asserts the text and the item labels.

Review evidence:

Behavior before. The body of the ODT holds two paragraphs and a table of contents with an index title and two entries. The export holds the two paragraphs only:

Intro paragraph.

Outro paragraph.

The document has two text items. _add_odf_child() sends the index element to the branch that reads images only, so the paragraphs inside text:index-body are never visited. Every index kind of ODF 1.2 has its own tag and meets the same branch.

Behavior after.

Intro paragraph.

Table of Contents

Chapter One	1

Section One	2

Outro paragraph.

Document tree: the index title and the entries are DocItemLabel.TEXT items in document order, between the two paragraphs, and no other item is added. The text:index-title-template of text:table-of-content-source stays out of the document: it is a template, and LibreOffice renders the text:index-title paragraph of the index body.

The index containers are transparent now, the same way text:section is. The containers are text:index-body and text:index-title, and they hold the entries of every index kind: text:table-of-content, text:alphabetical-index, text:illustration-index, text:table-index, text:object-index, text:user-index and text:bibliography. The hidden section behavior stays: text:display="none" sends the content to the invisible content layer, and the same holds for a hidden index.

Checks.

Check Command Result
Table of contents test, red first pytest tests/test_backend_opendocument.py -k table_of_contents without the source change 1 failed
Index kind tests, red first pytest tests/test_backend_opendocument.py -k index without the source change 6 failed
New tests, after the fix pytest tests/test_backend_opendocument.py 68 passed
Other ODF callers pytest tests/test_cli.py tests/test_input_doc.py 123 passed
Format and lint ruff format --check and ruff check on the two changed files All checks passed
Line limit scripts/check_max_lines.py 16 files over the limit, the same as main; the two changed files are exempted in .github/max-lines-ignore
Type check ty check 618 diagnostics, the same as main, none on the new lines

No reference-data changes: no fixture under tests/data/ holds an index element, and the new tests build their own documents.

Scope: this branch is rebased onto main at the writing time. The rebase keeps the hidden section handling of #4860.

@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

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

@mergify

mergify Bot commented Oct 10, 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)(?:\(.+\))?(!)?:

@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working odf Issue related to the OpenDocument format (ODT, ODS, ODP) backend labels Oct 13, 2026
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

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

The PR fixes the ODF backend so it keeps the text of a table of contents and of other index kinds. It treats the index container elements as transparent, in the same way as text:section. It adds tests for this.

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.

@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): no blocker found

This review covers the full diff at c6beb713ea. It read the code and did not run it.

The fix is small and handles a table of contents correctly. The main risk is that the same data loss stays for the other ODF index types. The reviewer must decide whether to widen the tag set in this PR or to track those types in a follow-up issue.

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

Comment thread docling/backend/opendocument_backend.py
Comment thread tests/test_backend_opendocument.py
@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Oct 13, 2026
A table of contents holds its visible text in the index containers, as
ordinary paragraphs. The backend matched none of them, so the element
reached the branch that reads images only and the paragraphs of the index
body were never visited.

The index containers now use the transparent branch of the section
element, so their paragraphs become text items. The index title template
stays out: it is not part of the rendered index.

Signed-off-by: Ryan Yang <ryanxys@gmail.com>
The index containers were matched for a table of contents only. An
alphabetical, illustration, table, object, or user index, and a
bibliography, hold their entries in the same containers, so the same
text was dropped.

All the index kinds are now matched. The test checks the item labels as
well as the text order, and covers each index kind.

Signed-off-by: Ryan Yang <ryanxys@gmail.com>
@ryanmeowy
ryanmeowy force-pushed the fix/odt-table-of-content branch from c6beb71 to e59721f Compare October 17, 2026 16:36
@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-lgtm AI first review found no blocker or major issue (advisory) labels Oct 17, 2026

@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): no blocker found

This review covers the full diff at e59721f16c. It read the code and did not run it.

I found no finding that decides the merge. The change makes the index containers transparent, the same way text:section already is, and the two new tests cover the table of contents and the other index kinds. The odfdo package in the environment has no class for these tags, so the tag-based match is needed.

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

This branch has not been deployed

No deployments
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) ai:review-lgtm AI first review found no blocker or major issue (advisory) bug Something isn't working odf Issue related to the OpenDocument format (ODT, ODS, ODP) backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ODT: a generated table of contents is dropped

1 participant