feat: add artifacts_dir parameter to export_to_markdown and export_to_html#552
Open
olijacklu wants to merge 3 commits intodocling-project:mainfrom
Open
feat: add artifacts_dir parameter to export_to_markdown and export_to_html#552olijacklu wants to merge 3 commits intodocling-project:mainfrom
olijacklu wants to merge 3 commits intodocling-project:mainfrom
Conversation
Contributor
|
✅ DCO Check Passed Thanks @olijacklu, all your commits are properly signed off. 🎉 |
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
|
Related Documentation 1 document(s) may need updating based on files changed in this PR: Docling Content LayersView Suggested Changes@@ -62,6 +62,32 @@
This ensures that both the main body and any detected headers or footers are present in the exported file.
+### Saving Images to a Directory
+
+When exporting to Markdown or HTML with `ImageRefMode.REFERENCED`, you can use the `artifacts_dir` parameter to automatically save images to a specified directory:
+
+```python
+from docling_core.types.doc.document import ImageRefMode
+
+# Export to Markdown with images saved to a directory
+markdown = doc.export_to_markdown(
+ image_mode=ImageRefMode.REFERENCED,
+ artifacts_dir="./images"
+)
+with open("output.md", "w") as f:
+ f.write(markdown)
+
+# Export to HTML with images saved to a directory
+html = doc.export_to_html(
+ image_mode=ImageRefMode.REFERENCED,
+ artifacts_dir="./images"
+)
+with open("output.html", "w") as f:
+ f.write(html)
+```
+
+The images are automatically extracted and saved to the specified directory, with the output referencing the saved image files.
+
The `export_to_text()` method produces clean plain text without Markdown decoration (no heading markers `#`, bold/italic markers, or hyperlink syntax), while still preserving list bullets, ordered list numbers, and table separators for readability. The `export_to_vtt()` method serializes documents with TrackSource data to valid WebVTT format with configurable timestamp and voice tag formatting.
All four export methods (`export_to_text()`, `export_to_markdown()`, `export_to_html()`, `export_to_vtt()`) support the `included_content_layers` parameter:
@@ -70,6 +96,9 @@
Additionally, `export_to_text()`, `export_to_markdown()`, and `export_to_html()` support:
- `page_no`: Optional[int] = None
- `page_break_placeholder`: Optional[str] = None
+
+The `export_to_markdown()` and `export_to_html()` methods also support:
+- `artifacts_dir`: Optional[Union[str, Path]] = None – When provided with `ImageRefMode.REFERENCED`, images are automatically saved to the specified directory and referenced in the output
The `export_to_vtt()` method has additional WebVTT-specific parameters:
- `omit_hours_if_zero`: bool = False – If True, omit hours when they are 0 in the timings (e.g., "00:11.000" instead of "00:00:11.000")Note: You must be authenticated to accept/decline updates. |
…_html Signed-off-by: Oliver Jack <olijackl@amazon.com>
dcd70b4 to
c076dc0
Compare
PeterStaar-IBM
previously approved these changes
Mar 17, 2026
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Author
|
Is the codecov check blocking or can this be merged? Happy to add any tests if needed |
Signed-off-by: Oliver Jack <125984975+olijacklu@users.noreply.github.com>
Author
|
@PeterStaar-IBM is this ok to merge? |
PeterStaar-IBM
requested changes
Mar 27, 2026
Signed-off-by: Oliver Jack <olijackl@amazon.com>
7d95e87 to
99ccd9c
Compare
Author
|
@PeterStaar-IBM @vagenas fixed changes |
PeterStaar-IBM
approved these changes
Mar 27, 2026
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.
Related to docling-project/docling#3094
Summary
artifacts_dirparameter toexport_to_markdown()andexport_to_html()ImageRefMode.REFERENCED, images are automatically saved to the specified directory_with_pictures_refs()methodUsage
Future feature
I also reference this feature in my issue but I haven't added it for now (let me know if you think it could be worth it):
image_path_prefixparameter to allow custom paths in the output (e.g., for CDN URLs or web server paths)