diff --git a/src/WrapImagesInGallery.php b/src/WrapImagesInGallery.php
index 7d85e89..0f5cf31 100644
--- a/src/WrapImagesInGallery.php
+++ b/src/WrapImagesInGallery.php
@@ -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*(?:
|
|\n)\s*/', $matches[0]);
+ $images = array_filter(preg_split('/\s*(?:
|
|\n)\s*/', $matches[0]), function($img) {
+ return !empty($img);
+ });
$galleryItems = array_map(function($img) {
return '' . trim($img) . '';
}, $images);