Conversation
convert_img reads src and data-src but not srcset, so a responsive image
that carries its URL only in srcset loses it:
<img srcset="photo-1x.jpg 1x, photo-2x.jpg 2x" alt="A photo">
renders as ![A photo]() - an empty destination with no indication that
anything was dropped. The existing data-src fallback already covers the
same situation for lazy-loaded images, where a placeholder data URI would
otherwise win over the real URL; srcset and data-srcset are the
responsive equivalents of that case and were not consulted.
Candidates are split on a comma followed by whitespace so that commas
inside a URL query string (?crop=1,2) are not mistaken for separators,
and the descriptor (2x, 800w) is stripped from the selected candidate.
Only the first candidate is used, since markitdown emits a single
destination and the first candidate is the one chosen at the default
density. When keep_data_uris is set, an embedded data URI in src is still
preferred, as before.
Author
|
@microsoft-github-policy-service agree |
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.
_CustomMarkdownify.convert_imgreadssrcanddata-srcbut notsrcset, so a responsive image that carries its URL only insrcsetloses it:renders as
![A photo]()- an empty destination, with no indication that anything was dropped. The existingdata-srcfallback already covers the same situation for lazy-loaded images, where a placeholder data URI would otherwise win over the real URL;srcsetanddata-srcsetare the responsive equivalents of that case, and neither was consulted.This adds a
srcsetparser and extends the fallback chain tosrc(when usable) ->data-src->data-srcset->srcset. Candidates are split on a comma followed by whitespace, so commas inside a URL query string (?crop=1,2) are not mistaken for separators, and the descriptor (2x,800w) is stripped from the selected candidate. Only the first candidate is used, since markitdown emits a single destination and the first candidate is the one a browser picks at the default density. Whenkeep_data_urisis set, an embedded data URI insrcis still preferred, as before.Adds
tests/test_img_srcset.py, covering the fallback order, the placeholder case, descriptor and whitespace handling, and the comma-in-URL case.