Skip to content

Commit

Permalink
fix: new line causes an empty gallery item
Browse files Browse the repository at this point in the history
  • Loading branch information
YUCLing committed Oct 27, 2024
1 parent 8bd71aa commit 4cb1fe9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/WrapImagesInGallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class WrapImagesInGallery
public function __invoke(Renderer $renderer, $context, string $xml): string
{
return preg_replace_callback('/'.self::MATCH_GALLERY_REGEX.'/m', function ($matches) {
$images = preg_split('/\s*(?:<br\/>|<br>|\n)\s*/', $matches[0]);
$images = array_filter(preg_split('/\s*(?:<br\/>|<br>|\n)\s*/', $matches[0]), function($img) {
return !empty($img);
});
$galleryItems = array_map(function($img) {
return '<FANCYBOX-GALLERY-ITEM>' . trim($img) . '</FANCYBOX-GALLERY-ITEM>';
}, $images);
Expand Down

0 comments on commit 4cb1fe9

Please sign in to comment.