Repository navigation
fix(md): keep the image of an inline SVG data URI #4925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blocker: SVG
ImageRefmakesPictureItem.get_image()raise instead of returningNoneTrigger: Markdown or HTML input with
andfetch_images=True. This is now the default path for such input.Cause: The new
ImageRefhasuri=data:image/svg+xml;...and no_pil.FloatingItem.get_image()returnsself.image.pil_image. For adata:URI,ImageRef.pil_imagecallsPILImage.open(BytesIO(decoded)). It has notry/except, so it raisesUnidentifiedImageError. This happens indocling_core/types/doc/common/reference.py(thepil_imageproperty) and indocling_core/types/doc/items/node.py(FloatingItem.get_image).Wrong result: Before this PR the picture had
image=None.get_image()then returnedNonefor a picture with no provenance, and callers skipped it. Now two paths crash:DoclingDocument._with_pictures_refscallsitem.get_image(doc=self)with no guard. It runs forexport_to_markdown,export_to_htmlandsave_as_*withimage_mode=ImageRefMode.REFERENCED. A document with one inline SVG can no longer be exported in this mode.BaseItemAndImageEnrichmentModel.prepare_elementindocling/models/base_model.py:197callselement.get_image(conv_res.document). The picture description, classification and similar enrichment stages will crash on the SVG picture.The docstring says
pil_imageis "not available" for such a ref. In fact it raises, and the new code does not guard the callers.Test gap: The tests use only
ImageRefMode.EMBEDDEDandexport_to_dict. Neither callspil_image. No test coversREFERENCEDmode orget_image()on the SVG picture.Fix: Do not hand out an
ImageRefthatpil_imagecannot open. Options:image=Noneand store the SVG payload elsewhere, for example in the picture meta.docling_coreso thatpil_imagereturnsNonefor non-raster mimetypes.Add a regression test that exports with
ImageRefMode.REFERENCEDand callsget_image(doc)on the SVG pictu…