Skip to content

Commit 64f1d74

Browse files
authored
Merge pull request #13 from YUCLing/main
fix: new line causes an empty gallery item
2 parents ea9688c + 4cb1fe9 commit 64f1d74

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Diff for: src/WrapImagesInGallery.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class WrapImagesInGallery
1313
public function __invoke(Renderer $renderer, $context, string $xml): string
1414
{
1515
return preg_replace_callback('/'.self::MATCH_GALLERY_REGEX.'/m', function ($matches) {
16-
$images = preg_split('/\s*(?:<br\/>|<br>|\n)\s*/', $matches[0]);
16+
$images = array_filter(preg_split('/\s*(?:<br\/>|<br>|\n)\s*/', $matches[0]), function($img) {
17+
return !empty($img);
18+
});
1719
$galleryItems = array_map(function($img) {
1820
return '<FANCYBOX-GALLERY-ITEM>' . trim($img) . '</FANCYBOX-GALLERY-ITEM>';
1921
}, $images);

0 commit comments

Comments
 (0)