Skip to content

feat: add image_dir and image_path_prefix to export_to_markdown - #718

Open
PramodKokadwar wants to merge 1 commit into
docling-project:mainfrom
PramodKokadwar:add-image-dir-export-param
Open

feat: add image_dir and image_path_prefix to export_to_markdown#718
PramodKokadwar wants to merge 1 commit into
docling-project:mainfrom
PramodKokadwar:add-image-dir-export-param

Conversation

@PramodKokadwar

@PramodKokadwar PramodKokadwar commented Aug 12, 2026

Copy link
Copy Markdown

What
Adds two optional parameters to DoclingDocument.export_to_markdown():

image_dir: Optional[Path] — when set (together with image_mode=ImageRefMode.REFERENCED), pictures are automatically saved as PNG files to this directory instead of requiring the caller to save images and rewrite URIs manually.
image_path_prefix: str — prefix prepended to each saved image's filename when building the Markdown reference (e.g. "images/", or a URL prefix for hosted assets).

Why
Fixes #3094. Today, using ImageRefMode.REFERENCED with export_to_markdown() requires manually iterating picture items, saving each image, and rewriting URIs before calling the export — this wraps that into the export call itself, reusing the existing internal _with_pictures_refs() helper (the same one save_as_markdown() already relies on).

Changes
docling_core/types/doc/document.py: new params on export_to_markdown(), docstring entries, and image-saving logic gated on image_dir is not None.
test/test_docling_doc.py: added test_export_to_markdown_image_dir (verifies image is saved and referenced with the prefix) and test_export_to_markdown_without_image_dir_is_unaffected (verifies default behavior is unchanged when the new params aren't used).

Testing
ruff check / ruff format --check: clean
mypy: clean, no new errors
Full test_docling_doc.py + test_serialization.py suites: no regressions (2 new tests pass; pre-existing unrelated Windows-path-separator failures are unchanged before/after this change)

@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

DCO Check Passed

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

@mergify

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

Allows DoclingDocument.export_to_markdown() to automatically save
referenced images to a directory and prefix their paths, instead of
requiring callers to save images and rewrite URIs manually.

Fixes docling-project/docling#3094

Signed-off-by: pramodkokadwar <pramodkokadwar@gmail.com>
@PramodKokadwar
PramodKokadwar force-pushed the add-image-dir-export-param branch from 92825b4 to 6a03bd5 Compare August 12, 2026 12:35
@PramodKokadwar PramodKokadwar changed the title Add image_dir and image_path_prefix to export_to_markdown feat: add image_dir and image_path_prefix to export_to_markdown Aug 12, 2026
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.

1 participant