diff --git a/src/MacroReplacer/ImageAndVideoMacroReplacer.php b/src/MacroReplacer/ImageAndVideoMacroReplacer.php
index a52b96e..bc2900a 100755
--- a/src/MacroReplacer/ImageAndVideoMacroReplacer.php
+++ b/src/MacroReplacer/ImageAndVideoMacroReplacer.php
@@ -1,44 +1,50 @@
- durch HTML oder Tags, abhängig vom Dateityp
- */
-class ImageAndVideoMacroReplacer implements MacroReplacerInterface
-{
- private string $sourceFolder;
-
- public function __construct(string $sourceFolder = '')
- {
- if (!str_ends_with($sourceFolder, '/')) {
- $sourceFolder .= '/';
- }
-
- $this->sourceFolder = $sourceFolder;
- }
-
- public function replace(string $haystack): string
- {
- return preg_replace_callback(
- '/]*>.*?]*>.*?<\/ac:image>/is',
- function ($match) {
- $attachmentFileName = $match[1];
- $fileExtension = pathinfo($attachmentFileName, PATHINFO_EXTENSION);
-
- //Distinguish between images and videos
- if (in_array($fileExtension, ['jpg', 'jpeg', 'png', 'gif'])) {
- return ' ';
- } elseif (in_array($fileExtension, ['mp4', 'avi', 'mkv', 'mov'])) {
- return 'Your browser does not support the video tag. ';
- } else {
- // By default, a link to the attachment is created
- return '' . $this->sourceFolder . $attachmentFileName . ' ';
- }
- },
- $haystack
- );
- }
-}
+ with HTML or tags, depending on the file type
+ */
+class ImageAndVideoMacroReplacer implements MacroReplacerInterface
+{
+ private string $sourceFolder;
+
+ public function __construct(string $sourceFolder = '')
+ {
+ if (! str_ends_with($sourceFolder, '/')) {
+ $sourceFolder .= '/';
+ }
+
+ $this->sourceFolder = $sourceFolder;
+ }
+
+ public function replace(string $haystack): string
+ {
+ return preg_replace_callback(
+ '/]*>.*?]*>.*?(?:(.*?)<\/ac:caption>)?.*?<\/ac:image>/is',
+ function ($match) {
+ $attachmentFileName = $match[1];
+ $caption = isset($match[2]) ? trim($match[2]) : '';
+ $fileExtension = pathinfo($attachmentFileName, PATHINFO_EXTENSION);
+
+ // Distinguish between images and videos
+ if (in_array($fileExtension, ['jpg', 'jpeg', 'png', 'gif'])) {
+ $imgTag = ' ';
+ if ($caption !== '') {
+ return ''.$imgTag.''.$caption.' ';
+ }
+
+ return $imgTag;
+ } elseif (in_array($fileExtension, ['mp4', 'avi', 'mkv', 'mov'])) {
+ return 'Your browser does not support the video tag. ';
+ } else {
+ // By default, a link to the attachment is created
+ return ''.$this->sourceFolder.$attachmentFileName.' ';
+ }
+ },
+ $haystack
+ );
+ }
+}