Repository navigation
feat(cli): link referenced images relative to the output file - #4842
DanielNg0729 wants to merge 3 commits into
Conversation
With `--image-export-mode referenced`, the CLI did not give `artifacts_dir` to the docling-core save methods. docling-core then took the link style from the output path: - An absolute `--output` gave absolute `file:///` links, so the output folder could not be moved or shared. - A relative `--output out` wrote the images to `out/out/<name>_artifacts`. Give a relative `<name>_artifacts` folder for JSON, YAML, HTML and Markdown. docling-core then writes the images next to the output file and links them with a relative path. Signed-off-by: Daniel Nguyen <danielnguyenh07@gmail.com>
Convert an HTML file with a local image in referenced mode. Check that the Markdown, HTML, JSON and YAML outputs link the image relative to the output file, for absolute and relative `--output` and `--output-file` paths, and that the image folder is not nested twice. Signed-off-by: Daniel Nguyen <danielnguyenh07@gmail.com>
The `--image-export-mode` help now says that referenced images go to a `<name>_artifacts` folder next to the output file, and that the output links them with a relative path. Update the CLI reference to match. Signed-off-by: Daniel Nguyen <danielnguyenh07@gmail.com>
|
✅ DCO Check Passed Thanks @DanielNg0729, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
AI triage (advisory)Checked commit The PR adds a Topic labels added: CI safety: no concern found. A maintainer must still approve CI. 2 related pull request(s) in the same code
The |
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the full diff at 581207cfe3. It read the code and did not run it.
The fix correctly passes a relative artifacts_dir to every save_as_* call site so docling-core stores images next to the output file and links them with a relative path. The installed docling-core 2.100.0 accepts artifacts_dir on all four methods and its _get_output_paths logic correctly resolves a relative dir against filename.parent. Tests cover both relative and absolute --output paths and the --output-file case. No blocking issues found; verify CI is green.
A maintainer makes the merge decision. This review never approves the pull request.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Hi maintainers, this PR makes the CLI write portable image links in referenced mode. After this change, you can move or share the output folder and the images still open.
Issue resolved by this Pull Request:
Resolves #3678
Summary
With
--image-export-mode referenced,export_documentscallssave_as_markdown(filename=..., image_mode=...)withoutartifacts_dir. The JSON, YAML and HTML exports do the same. docling-core then chooses the link style from the shape of the output path (DoclingDocument._get_output_paths):--output.(default)doc_artifacts/doc_artifacts/image_….pngoutout/out/doc_artifacts/out/doc_artifacts/image_….pngD:\outD:\out\doc_artifacts\file:///D:/out/doc_artifacts/image_….pngfile:///links. The images do not load after you move the folder or open it on another machine.out/out/doc_artifacts/. This is docling-core#362.Changes
_artifacts_dir(output_path)indocling/cli/export_utils.py, returns the relative folder<name>_artifacts. This is the same name as the docling-core default, so the folder layout does not change.export_documentsgives this folder tosave_as_json,save_as_yaml,save_as_html(normal and split-page) andsave_as_markdown. Whenartifacts_diris relative, docling-core puts the folder next to the output file and links the images relative to that file. docling-core#399 suggested this approach.convert-remoteuses the sameexport_documents, so it also gets the fix.--image-export-modehelp text anddocs/reference/cli.mdnow say where the images go.The fix is only in the CLI. It needs no new docling-core release, because all four save methods accept
artifacts_dirsince docling-core 2.98 (the current minimum pin). The Python API does not change:doc.save_as_markdown("/abs/doc.md", image_mode=ImageRefMode.REFERENCED)still writes absolute links. That fix must be made in docling-core, for example with docling-core#363.Behaviour change for JSON and YAML
A JSON or YAML file written to an absolute
--outputnow has relative image URIs. Today you get the same result with the default--output .. docling-core opens a relative URI from the current directory (ImageRef.pil_image). So to load the images again from such a file (withenable_local_fetch=True), you must run from the output folder. Do you prefer to keep absolute URIs for JSON and YAML? If so, I can limit the change to Markdown and HTML.Known limit: HTML on Windows
docling-core 2.100.0 writes the HTML
srcwithquote(str(uri)). On Windows the relative link is thendoc_artifacts%5Cimage_….png. docling-core#772 fixes this on docling-coremain, but no release has it yet. Onmain, the Windows link is the full absolute path, which is also encoded (C%3A%5CUsers%5C…), so this PR does not make it worse. The Markdown link is correct on all platforms, and the HTML link is correct on Linux and macOS.Checklist: