Skip to content

Don't use void tags / output XML  #307

@KjellMorgenstern

Description

@KjellMorgenstern

Can jekyll_picture_tag output closed img tags?

{% picture {{ post.image }} preset="thumbnail" %}

produces a void tag like
<img preset="thumbnail" src="/generated/assets/images/my_post.png" srcset="/generated/assets/images/my_post-175-43e233202.webp 175w" sizes="() 100vw">

XML parsers frown on this, e.g when the output gets fed to a newsfeed, it should be
<img preset="thumnail" src=... />

with a closing />

To work around this, I use (*)

  {% capture img_tag %}
    {% picture {{ post.image }} preset="thumbnail" %}
  {% endcapture %}
  {% assign img_tag = img_tag | replace: '>', ' />' %}
  {{ img_tag | replace: ' />/', '/>' }}

and this seems to work. However, it looks bad, and I think it will fail on a more complex use case. Can jekyll_picture_tag simply close the tag? Or am I missing somthing important?

(*) if its a few images, just manually write the img tag and add the thumbnail to assets

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions