erusev / parsedown

Better Markdown Parser in PHP
https://parsedown.org
MIT License
14.69k stars 1.12k forks source link

Convert <img> into <picture> #810

Open CyrilMazur opened 3 years ago

CyrilMazur commented 3 years ago

Hi,

I'm looking at automatically converting <img> tags into <picture> tags. For example, converting this

![foo](image.jpg)

into this

<picture>
  <source type="image/webp" srcset="image.webp">
  <img src="image.jpg">
</picture>

I've reached this point:

protected function inlineImage($excerpt)
{
  $image = parent::inlineImage($excerpt);

  $image['element']['name'] = 'picture';

  return $image;
}

And the result is

<picture src="image.jpg" alt="foo"></picture>

But now I'm stuck. How do I add children elements into <picture>? 🤔