feat: add image_dir and image_path_prefix to export_to_markdown - #718
Open
PramodKokadwar wants to merge 1 commit into
Open
feat: add image_dir and image_path_prefix to export_to_markdown#718PramodKokadwar wants to merge 1 commit into
PramodKokadwar wants to merge 1 commit into
Conversation
Contributor
|
✅ DCO Check Passed Thanks @PramodKokadwar, all your commits are properly signed off. 🎉 |
Contributor
Merge Protections🔴 1 of 2 protections blocking · waiting on 👀 reviews
🔴 Require two reviewer for test updatesWaiting for
This rule is failing.When test data is updated, we require two reviewers
Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
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
force-pushed
the
add-image-dir-export-param
branch
from
August 12, 2026 12:35
92825b4 to
6a03bd5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)