In your (awesome) documentation you are showing an example how to replace an image with a srcset:
<?php
Kirby::plugin('your/plugin', [
'tags' => [
'imageset' => [
'attr' => array_merge(
Kirby\Text\KirbyTag::$types['image']['attr'],
[
'srcset'
]),
'html' => function($tag) {
$file = $tag->file($tag->value());
$srcset = $tag->srcset ? explode(',', $tag->srcset): null;
$result = Kirby\Text\KirbyTag::$types['image']['html']($tag);
if (! $file === true || is_null($srcset) === true) {
return $result;
}
$pattern = '/<img.*>/i';
// build a new image tag with the srcset
$image = Html::img($tag->src, [
'width' => $tag->width,
'height' => $tag->height,
'class' => $tag->imgclass,
'title' => $tag->title,
'alt' => $tag->alt ?? ' ',
'srcset' => $file->srcset($srcset),
]);
// replace the old image tag
$result = preg_replace($pattern, $image , $result);
return $result;
}
]
]
]);
I believe that there is a small error in the regular expression you are using because it selects the maximum match of all html enties up to the first line break. This unfortunately includes parts of the figcaption and will therefore lead to unwanted results.
As far as I can see, this small change would be sufficent to select only the smallest possible match:
$pattern = '/<img.*?>/i';