Skip to content

feat(markdown): include table image in Markdown export when available#680

Open
maxmilian wants to merge 1 commit into
docling-project:mainfrom
maxmilian:feat/table-image-markdown-export
Open

feat(markdown): include table image in Markdown export when available#680
maxmilian wants to merge 1 commit into
docling-project:mainfrom
maxmilian:feat/table-image-markdown-export

Conversation

@maxmilian

Copy link
Copy Markdown
Contributor

Closes #474.

What

MarkdownTableSerializer only ever emitted the text/HTML table grid — TableItem.image was ignored entirely, unlike MarkdownPictureSerializer, which already honors image_mode (PLACEHOLDER / EMBEDDED / REFERENCED) for pictures.

Change

  • Extracted the shared image-emission logic (previously MarkdownPictureSerializer._serialize_image_part) into a module-level function reused by both the picture and table serializers — no behavior change to the existing picture path (verified byte-for-byte identical branches).
  • Moved _image_to_base64 from PictureItem up to the shared FloatingItem base so TableItem (which is also a FloatingItem) can use it.
  • MarkdownTableSerializer.serialize now appends the table image alongside the existing text table when item.image is set and image_mode is not PLACEHOLDER — the text table is preserved so this is purely additive.

Design choice (open in the issue, unconfirmed by a maintainer)

I'd asked in the issue whether the image should replace or be emitted alongside the text table, and whether it should reuse image_mode or a new dedicated option. I went with alongside + reuse existing image_mode, since:

  • it requires no new public API surface, and
  • replacing the text table by default would be a breaking output change for existing consumers who already rely on the Markdown table text (e.g. for RAG chunking).

Happy to adjust if a maintainer prefers different behavior.

Backward compatibility

Tables without a generated image (item.image is None — the common case, since table images require the generate_table_images pipeline option) see zero output change, even if image_mode is explicitly set to something other than PLACEHOLDER. Covered by a dedicated regression test.

Testing

Added 3 new tests in test/test_serialization.py:

  • test_md_table_with_image_embeddedEMBEDDED mode, image present
  • test_md_table_with_image_referencedREFERENCED mode, image present (asserts exact output)
  • test_md_table_without_image_unaffected_by_image_mode — no image present, asserts byte-exact no-op regardless of image_mode

Full suite: uv run pytest -q → 545 passed, 6 skipped (unrelated to this change).
ruff check / ruff format --check / mypy docling_core test all clean.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

DCO Check Passed

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

@mergify

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

@maxmilian
maxmilian marked this pull request as ready for review July 8, 2026 15:51
@maxmilian
maxmilian force-pushed the feat/table-image-markdown-export branch from e1a0d20 to c3f2ad9 Compare July 18, 2026 10:47
@maxmilian

Copy link
Copy Markdown
Contributor Author

Rebased and force-pushed to resolve the conflict. It turned out to be more than a textual conflict: #664 split the monolithic document.py into focused modules after this branch was opened, so the original diff no longer applied. I've reworked the change onto the new layout:

  • _image_to_base64 moved from PictureItem up to the shared FloatingItem base — now in docling_core/types/doc/items/node.py (dropping the now-unused base64/BytesIO imports from items/picture/picture.py).
  • _serialize_image_part extracted from MarkdownPictureSerializer into a module-level helper in transforms/serializer/markdown.py, called by both the picture and table serializers.
  • MarkdownTableSerializer now emits the table image alongside the text grid when item.image is set and image_mode is not PLACEHOLDER; tables without an image stay a strict no-op.

The behavior and public surface are unchanged from the original PR. Verified on the new base: test_serialization.py (50) plus the doclang/doc/latex serialization suites (220 total) pass, and the three new table-image tests (embedded / referenced / no-op) go red without the change. ruff check, ruff format, and mypy are clean on the touched files.

MarkdownTableSerializer previously ignored TableItem.image entirely, only
emitting the text grid, unlike MarkdownPictureSerializer which honors
image_mode for pictures.

Extract the shared image-emission logic into a module-level
_serialize_image_part() usable by both serializers, and move
_image_to_base64 up from PictureItem to the shared FloatingItem base so
TableItem can call it too.

MarkdownTableSerializer now appends the table image alongside the text
table when item.image is set and image_mode is not PLACEHOLDER. Tables
without a generated image (the common case) see no output change.

Reworked onto the post-docling-project#664 module split (items/node.py, items/picture,
transforms/serializer/markdown) after the original branch went stale.

Closes docling-project#474

Signed-off-by: Max Hsu <maxmilian@gmail.com>
@maxmilian
maxmilian force-pushed the feat/table-image-markdown-export branch from c3f2ad9 to b361bb7 Compare July 19, 2026 23:34
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.

Feature Request: Support table image output in Markdown export

1 participant