From 4cb1fe90edfe5b64facf2d6db9d7990cba773b71 Mon Sep 17 00:00:00 2001 From: YUCLing Date: Sun, 27 Oct 2024 13:13:42 +0800 Subject: [PATCH] fix: new line causes an empty gallery item --- src/WrapImagesInGallery.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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);