docling-project / docling-project/docling-core

Feature Request: Support table image output in Markdown export

Open
#474 5 comments 1 reaction 0 assignees View on GitHub
Dominant language
HTML
Stars
282
Forks
214
Avg merge
2d 15h
Merged PRs (30d)
21

Description

# Feature Request: Support table image output in Markdown export

## Description
When exporting a document to Markdown using `docling`, `TableItem` elements are currently only exported as text-based Markdown tables (or HTML). Even when `image_mode` is set to `ImageRefMode.REFERENCED` or `ImageRefMode.EMBEDDED` and `generate_table_images=True` is used, the table images are not included in the Markdown output.

This contrasts with `PictureItem` elements, which correctly respect the `image_mode` setting and output image links.

This issue was originally reported in `docling` (https://github.com/docling-project/docling/issues/2820), but the root cause and fix lie within `docling-core`'s serialization logic.

## Current Behavior
- `MarkdownTableSerializer` (in `docling_core`) strictly exports tables as text/markdown grids.
- It ignores the `image_mode` parameter for tables.
- It ignores the presence of `item.image` (if populated).

## Expected Behavior
If `image_mode` is set to `REFERENCED` or `EMBEDDED`, and the `TableItem` has an associated image (`item.image`), the serializer should:
1. Preferentially output the image (or include it alongside the text, depending on desired behavior, but likely behaving similar to `PictureItem`).
2. Generate the appropriate Markdown image syntax (e.g., `![Table](image_path.png)` or embedded base64).

## Proposed Solution
Modify `MarkdownTableItemSerializer` (or `MarkdownTableSerializer`) in `docling_core/transforms/serializer/markdown.py`.

The `serialize` method should be updated to check `self.params.image_mode`:

```python
# Pseudo-code logic to be added to serialize()

if self.params.image_mode in [ImageRefMode.REFERENCED, ImageRefMode.EMBEDDED] and item.image:
# Logic similar to MarkdownPictureSerializer
image_link = self._get_image_link(item) # Helper to generate path/base64
return getattr(self, "create_ser_result")(text=f"![{label}]({image_link})", span_source=item)

# Fallback to existing text table generation
...

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.