Skip to content

fix(serializer): serialize table footnotes in Markdown and HTML#675

Open
Kavishkagaya wants to merge 1 commit into
docling-project:mainfrom
Kavishkagaya:fix/serialize-table-footnotes-496
Open

fix(serializer): serialize table footnotes in Markdown and HTML#675
Kavishkagaya wants to merge 1 commit into
docling-project:mainfrom
Kavishkagaya:fix/serialize-table-footnotes-496

Conversation

@Kavishkagaya

Copy link
Copy Markdown

Fixes #496

Problem

Table footnotes are silently dropped from Markdown and HTML output. The footnotes are correctly stored on TableItem.footnotes in the document model (they appear in the JSON), but never make it into the serialized text — so a table renders with dangling * / ** markers whose definitions have vanished. As #496 notes, this also affects chunking, which relies on serialization.

Root cause

After footnote handling was delegated to the parent FloatingItem, the serialize_footnotes hook was added to the doc serializer — but the table serializers were never wired to call it. They call serialize_captions (so captions appear) but not serialize_footnotes, so the method was effectively dead code and the footnotes had nowhere to go.

Fix

  • MarkdownTableSerializer — emit the table's footnotes after the table body, mirroring the existing caption handling.
  • HTMLTableSerializer — emit the footnotes after the closing </table>.
  • HTMLDocSerializer — add a serialize_footnotes override so footnotes are HTML-escaped and wrapped in <div class="footnote">, matching the existing serialize_captions override (the base method returns raw text, which is unsafe for HTML).

Evidence

Using the table_parsing_test.pdf attached to #496 (digital PDF, standard pipeline). The table has two footnotes assigned; before the fix both are missing from the Markdown, after the fix both are present:

Before (export_to_markdown()):

| 442-D | Legacy Support | 1 | Archived** |

This final paragraph provides a clear end-of-section marker. ...

After:

| 442-D | Legacy Support | 1 | Archived** |

*Note: The 'Pending' status indicates that the asset is awaiting final security validation. **Note: 'Archived' items are scheduled for decommissioning at the end of the current fiscal year.

This final paragraph provides a clear end-of-section marker. ...

HTML output, after the fix, now emits (escaped):

<table>...</table><div class="footnote">*Note: The 'Pending' status ...</div><div class="footnote">**Note: 'Archived' items ...</div>

Note: #496 only mentions Markdown, but HTML was affected too — this PR fixes both.

Testing

  • Added a regression test (test_table_footnotes_serialized_to_markdown_and_html) that builds an in-memory DoclingDocument with a table + two footnotes and asserts they survive both export_to_markdown() and export_to_html().
  • Full existing suites pass with no regressions: serialization (test_serialization.py, test_serialization_doctag.py, test_latex_serialization.py, test_azure_serializer.py) and chunking (test_hierarchical_chunker.py).
  • ruff check and ruff format --check clean.

…ing-project#496)

Since footnote handling was delegated to the parent FloatingItem, table
footnotes were silently dropped from Markdown and HTML output (and from
chunking, which relies on serialization). The `serialize_footnotes` hook
existed on the doc serializer but was never invoked by the table
serializers, so the footnotes stored on `TableItem.footnotes` never
reached the output.

- MarkdownTableSerializer: emit the table's footnotes after the table
  body, mirroring the existing caption handling.
- HTMLTableSerializer: emit the footnotes after the closing </table>.
- HTMLDocSerializer: add a serialize_footnotes override so footnotes are
  HTML-escaped and wrapped in <div class="footnote"> (the base method
  returns raw text, matching the existing serialize_captions override).
- Add a regression test asserting table footnotes survive both exports.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Kavishka Rambukwella <90164480+Kavishkagaya@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

DCO Check Passed

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

@mergify

mergify Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 2 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require two reviewer for test updates 👀 reviews
🟢 Enforce conventional commit

🔴 Require two reviewer for test updates

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

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

@Kavishkagaya

Copy link
Copy Markdown
Author

Aware of the related #545 and #569 targeting the same issue — opening this as a smaller, focused alternative:

Happy to fold this into either of the other PRs if the maintainers prefer to consolidate.

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: Table footnotes missing from markdown serialization after commit dda9c88

1 participant