Skip to content

fix(jats): preserve table footnotes - #4818

Merged
vagenas merged 5 commits into
docling-project:mainfrom
AryanRG:fix/jats-table-footnotes-4796
Nov 6, 2026
Merged

vagenas merged 5 commits into
docling-project:mainfrom
AryanRG:fix/jats-table-footnotes-4796

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

JATS conversion drops direct table-wrap-foot/fn notes. This change attaches each nonempty note as one FOOTNOTE owned and referenced by its table, preserving source order, formatting, hyperlinks, inline formulas and literal citations such as [8]. A note paragraph keeps a word boundary to what precedes it, including the note label, by the same rule main uses for article-level footnotes.

Refs #4796. This covers table notes only; author notes, nested fn-group containers, bare table-wrap-foot paragraphs and xref resolution remain separate work. Existing fn-group behavior is unchanged.

Representation

Each note is an empty FOOTNOTE item under the table, referenced from TableItem.footnotes. Its content is an inline group of runs, similar to the article-level footnote list items. The runs keep their source whitespace under the InlineGroup contract from #3891, so <sup>a</sup>CO<sub>2</sub>e has no space after the marker. Text runs carry the FOOTNOTE label, so label filtering and chunk metadata classify them as note content; formula runs keep FORMULA.

The change does not modify pyproject.toml or uv.lock.

Known serializer limits (docling-core 2.106.0)

The document keeps the complete notes. These are export issues, reported in docling-project/docling-core#973:

Note text appears once in both formats. If only the FOOTNOTE label is excluded, the note text runs are removed but an inline formula can remain, because it keeps the FORMULA label.

Checklist:

  • Added synthetic regressions for parser behavior and exports.
  • Added label-filter and chunk-metadata coverage.
  • Regenerated and reviewed the affected reference outputs.
  • Kept the change inside the JATS backend, its tests and reference data.

Review evidence:

  • Python 3.10.22 with docling-core 2.106.0, as locked by main: tests/test_backend_jats.py, tests/test_backend_jats_table_footnotes.py, tests/test_backend_jats_sub_articles.py and tests/test_data_gen_flag.py: 120 passed.
  • On main without this change, 20 of the 23 table-note tests fail. The 3 that pass check that empty notes and bare paragraphs add no footnotes.
  • tests/test_inline_whitespace_contract.py: 27 passed. One docx equation case fails identically on main in my environment, which lacks an optional docx math dependency.
  • make validate: passed, including Ruff, the formatter, ty, Tach, module coverage and the max-lines checks.
  • The full repository suite was not run locally.

Exactly six existing references change: JSON, Markdown and indented text for pntd.0008301.nxml and pone.0234687.nxml. They represent 20 notes across six tables. Outside the table notes, the document items match main. The Markdown files only gain lines: the 20 note paragraphs after their tables, plus the empty paragraphs described above. jats_backend.py is now 1547 lines, so it is added to the [warn] list in .github/max-lines-ignore.

Reference-data changes require two approving reviewers under the repository contribution policy.

Signed-off-by: Aryan Rajesh Ganjoo <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

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

@mergify

mergify Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 All 2 merge protections satisfied — ready to merge.

Show 2 satisfied protections

🟢 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)(?:\(.+\))?(!)?:

🟢 Require two reviewer for test updates

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/xml/jats_backend.py 88.00% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@AryanRG
AryanRG marked this pull request as ready for review October 15, 2026 14:30
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working xml issue related to supported schema-specific XML formats labels Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

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

The JATS backend now keeps table-wrap-foot/fn notes. Each non-empty note becomes a FOOTNOTE item under its table, referenced from TableItem.footnotes. The inline runs keep their formatting, hyperlinks and formulas. The PR adds a new test file and updates two JATS reference documents.

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

3 related pull request(s) in the same code
PR State Signal Assessment
#5039 open changes the same code related: Both PRs edit _add_table in jats_backend.py. That PR sets the parent of caption items. This PR adds table footnotes. The two changes are independent.
#5078 open also references issue #4796 related: Both PRs touch JATS table handling and refer to the same issue. That PR keeps tables published as an image. This PR keeps footnotes of parsed tables. They solve different problems.
#3891 merged referenced as #3891 related: That PR is merged. It added the InlineGroup whitespace contract and _trim_segment_edges. This PR relies on that code and does not repeat it.

Reference data changes

Change Files
structure 2
text 4
  • structure tests/data/jats/groundtruth/pntd.0008301.nxml.json: footnote: 0 → 6
  • structure tests/data/jats/groundtruth/pone.0234687.nxml.json: footnote: 0 → 71
  • text tests/data/jats/groundtruth/pntd.0008301.nxml.itxt: +273 / -264 lines
  • text tests/data/jats/groundtruth/pntd.0008301.nxml.md: +10 / -0 lines
  • text tests/data/jats/groundtruth/pone.0234687.nxml.itxt: +850 / -762 lines
  • text tests/data/jats/groundtruth/pone.0234687.nxml.md: +66 / -0 lines

Assessment: expected. The footnote count rises in two JATS reference files (0 to 6 and 0 to 71), which matches the new table footnote handling. The new footnote items also explain the added lines in the .md files and the shifted item numbers in the .itxt files.

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 ad7506810f. It read the code and did not run it.

The change keeps table notes visible by using an empty FOOTNOTE wrapper with the note text in child runs. This is a workaround for the table serializer in docling-core 2.100.0. I could not read the installed docling_core source, so I did not check the claim about how its serializers treat referenced footnotes.

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

Comment thread docling/backend/xml/jats_backend.py Resolved
@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Oct 15, 2026
@AryanRG

AryanRG commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Resolving the conflict exposed a compatibility problem with released docling-core 2.105.0: it renders referenced footnotes from their own text, so this PR's empty wrappers add empty HTML footnotes and extra Markdown spacing. The note content still appears once. Putting text on the wrappers as well makes it appear twice on 2.105.0; removing the child runs instead loses exports on older supported cores.

Which direction would you prefer?

  • Table-owned inline groups: tested exports match across 2.103.1–2.105.0, but TableItem.footnotes stays empty.
  • Referenced plain-text notes with a minimum of core 2.105.0: loses rich formatting and still omits the notes from DocTags.
  • A core serializer fix first, retaining both references and rich content.

I've kept the merge update local pending that decision. Happy to try another representation if I've missed one.

@PeterStaar-IBM

Copy link
Copy Markdown
Member

Hi @AryanRG, thank you for this pull request.

It has a merge conflict with main. Please rebase your branch on the latest main and resolve the conflict:

git fetch upstream
git rebase upstream/main
# resolve the conflicts, then:
git push --force-with-lease

We can continue with the review and CI after that.

AryanRG commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @PeterStaar-IBM. The saved merge update exposed the core compatibility problem described above. Before I update the branch, could you confirm whether table-owned inline groups are acceptable, or whether we should fix the core serializer first to retain footnote references and rich content?

@vagenas

vagenas commented Nov 4, 2026

Copy link
Copy Markdown
Member

@AryanRG on your question: this PR's scope is producing the correct DoclingDocument, so let's keep referenced footnotes with rich content (and not adapt the representation to a serializer's current output). For any serialization issues (e.g. empty HTML footnotes, extra Markdown spacing), I'd suggest opening an issue in docling-core, or link any existing one. This PR should not need to wait for such docling-core fixes.

Two changes for your update, because your saved merge predates #3891, which merged today:

  • main no longer has _strip_segments, so _add_table_footnotes must call _trim_segment_edges. This helper keeps the whitespace between runs.
  • main now requires docling-core 2.106.0, which joins InlineGroup runs with no separator, so the goldens need regenerating. Runs should follow the source: <sup>a</sup>CO<sub>2</sub>e has no space after the marker, so no space is needed there, even if the Markdown then reads aCO2e (that'd be a point for docling-core).

Resolve the conflicts with #3891 (InlineGroup whitespace contract):

- _add_table_footnotes trims the note edges with _trim_segment_edges,
  which replaces _strip_segments, so the whitespace between runs stays.
- _walk_inline_formula keeps the ext-link pass-through for table notes
  and uses main's paragraph boundary, so the paragraph_breaks option
  is no longer needed.
- Table-note tests expect runs with their source whitespace.
- Regenerate the pntd.0008301 and pone.0234687 references with
  docling-core 2.106.0.
- Add jats_backend.py to the max-lines warn list (1547 lines).

Signed-off-by: Aryan Rajesh Ganjoo <[email protected]>
Add a regression for `<sup>a</sup>CO<sub>2</sub>e`: the runs follow the
source, so no space follows the marker. Describe the referenced FOOTNOTE
item and its inline runs as the document representation, not as a
serializer workaround.

Signed-off-by: Aryan Rajesh Ganjoo <[email protected]>
@github-actions github-actions Bot 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 Nov 4, 2026
@AryanRG

AryanRG commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @vagenas, updated. I merged current main and kept the referenced FOOTNOTE items with their rich inline runs. _add_table_footnotes now uses _trim_segment_edges and main's paragraph boundary, so the runs follow the source and <sup>a</sup>CO<sub>2</sub>e gets no added space.

The pntd/pone references are regenerated with docling-core 2.106.0 and match main outside the table notes. The JATS and table-note tests and make validate pass locally. I opened docling-project/docling-core#973 for the empty HTML footnotes and extra Markdown blank lines; Markdown sub/superscript is already covered by docling-project/docling-core#802 and docling-project/docling-core#661.

@github-actions github-actions Bot added the ai:ci-needs-care AI triage: check CI-safety findings before you approve CI label Nov 4, 2026
@PeterStaar-IBM

Copy link
Copy Markdown
Member

Hi @AryanRG, thank you for this pull request.

It has a merge conflict with main. Please rebase your branch on the latest main and resolve the conflict:

git fetch upstream
git rebase upstream/main
# resolve the conflicts, then:
git push --force-with-lease

We can continue with the review and CI after that.

@github-actions github-actions Bot removed the ai:ci-needs-care AI triage: check CI-safety findings before you approve CI label Nov 6, 2026
@github-actions github-actions Bot added the ai:ci-safe AI triage found no CI-safety concern (advisory) label Nov 6, 2026

@vagenas vagenas 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.

Thanks @AryanRG. I merged main into your branch to resolve the conflict with #4809. (You can update the line about .github/max-lines-ignore in the description, since main already lists jats_backend.py.)

@vagenas
vagenas merged commit c715294 into docling-project:main Nov 6, 2026
34 checks passed
ska2704 added a commit to ska2704/docling that referenced this pull request Nov 6, 2026
Regenerated the JATS reference data on top of the merged code to resolve
the conflicts with docling-project#4818.

Signed-off-by: SK Arin <[email protected]>
@Jinyong-Li Jinyong-Li mentioned this pull request Nov 6, 2026
3 tasks done
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 xml issue related to supported schema-specific XML formats

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants