Repository navigation
fix(markdown): resolve relative images for local sources - #4816
Conversation
MarkdownBackendOptions.source_uri resolves relative image paths, but MarkdownFormatOption did not fill it in from the input source, so a local Markdown file converted with fetch_images=True could not load its own relative images. The other backends that use source_uri, HTML, AsciiDoc, and LaTeX since docling-project#4697, fill it in from the input. Add the backend_options_for_input override to MarkdownFormatOption, the same way HTMLFormatOption and AsciiDocFormatOption already do it. Signed-off-by: Abdel <62770500+hktitof@users.noreply.github.com>
|
✅ DCO Check Passed Thanks @hktitof, 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 This pull request sets backend options for local Markdown inputs to include the source URI. This allows the Markdown backend to resolve relative image paths. Topic labels added: CI safety: no concern found. A maintainer must still approve CI. 1 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 f9db1ccc6f. It read the code and did not run it.
The fix correctly mirrors the existing AsciiDocFormatOption.backend_options_for_input pattern and the test covers both str and Path sources. Verify that the model_validate coercion of a local str path to PurePath works as expected, since AsciiDocFormatOption uses the same implicit coercion while LatexFormatOption explicitly converts to Path(source). No blocker found.
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! |
|
thanks for the review and merge @dolfim-ibm, happy to contribute to docling! |
this fixes relative images not loading when you convert a local markdown file
i hit this while converting a local .md file that points at an image with a relative path
what is wrong
MarkdownBackendOptions has a source_uri field and the markdown backend uses it as the base path to resolve relative image paths, but MarkdownFormatOption never fills it in from the input source
so when you convert a local markdown file with fetch_images and enable_local_fetch on, the image is never loaded and you get this warning
the other backends that use source_uri already fill it in, HTMLFormatOption and AsciiDocFormatOption have a backend_options_for_input override, and LatexFormatOption got one in #4697 for the same kind of problem
markdown was the one left out
steps to reproduce
raw output on master before the change, for both a str path and a Path
the fix
add the same backend_options_for_input override to MarkdownFormatOption that HTMLFormatOption and AsciiDocFormatOption already have, so source_uri is filled from a local str or Path source
after the change
if you set source_uri yourself it still wins, backend_options=None still returns None, and a DocumentStream is left alone, same as the HTML and AsciiDoc versions
tests
added one parametrized test in tests/test_backend_markdown.py that covers both str and Path input, it fails on master and passes with the fix
i also ran
note: there are open PRs that touch document_converter.py and tests/test_backend_markdown.py, i checked them and none fixes this same defect, so the file overlap is just a rebase cost if it happens
all of this is cpu only on a local sandbox, no gpu and no model weights involved
Checklist
Review evidence
Before: on main,
convert("doc.md")withfetch_images=True, enable_local_fetch=Truegivespictures/loaded = (1, 0)and logs the base_path warning, the picture item has no image.After: the same call gives
pictures/loaded = (1, 1)for both a str and a Path source, and the loaded image keeps its original 7x5 pixels.Checks performed:
pytest tests/test_backend_markdown.py-> 36 passedpytest tests/test_backend_markdown.py tests/test_backend_asciidoc.py tests/test_backend_text_encoding.py-> 112 passedassert None is not None), so it fails without the changepython3 scripts/check_max_lines.py --max-lines=1500on both files -> passgit diff --check-> pass