Markdown image rendering seems to produce invalid HTML (empty attribute srcset="")
#2
|
Checking https://russie-libertes.org/media (renders a list of social network logos by rendering markdown with remark Astro pipeline) at https://validator.w3.org/nu/
Is it a known issue? Is it possible to fix this? |
Replies: 2 comments 5 replies
|
Might be a bug? Can you share a reproduction? |
|
Yep, looks like a bug. I made a tiny content collection with the same Markdown image and could reproduce it in both Astro 7.0.9 and 7.2.0, so it doesn't seem tied to your custom component. With: the generated HTML contains: <img
alt="LinkedIn"
src="/_astro/linkedin....svg"
width="24"
height="24"
srcset=""
>It seems to happen when a local SVG goes through Astro's Markdown image pipeline. Since there are no responsive variants for the SVG, I'd expect As a workaround, I moved the SVG to That renders without the empty
|

Filed it: withastro/astro#17871
Minimal reproduction: https://github.com/jx-grxf/astro-markdown-srcset-repro
One correction to what I wrote above: it isn't SVG-specific. A 2000×1000 PNG going through the same content collection gets
srcset=""as well, so it affects every Markdown image rendered through the content layer, not just images without responsive variants of a particular type.The same Markdown placed in
src/pages/legacy.mdrenders without the attribute. That path (vite-plugin-markdown/images.ts) only setssrcsetwhensrcSet.values.length > 0, whilecontent/runtime.tssets it unconditionally and the serializer keeps empty strings on purpose. Details are in the issue.The
public/…