shortcode->getHandlers()->add('image-caption', function (ShortcodeInterface $sc) { $plugin = $this->grav['plugins']->getPlugin('story-blocks'); $page = $plugin ? $plugin->getCurrentPage() : null; $imageName = htmlspecialchars($sc->getParameter('image', ''), ENT_QUOTES); $alt = htmlspecialchars($sc->getParameter('alt', ''), ENT_QUOTES); $caption = htmlspecialchars($sc->getParameter('caption', ''), ENT_QUOTES); $credit = htmlspecialchars($sc->getParameter('credit', ''), ENT_QUOTES); $width = $sc->getParameter('width', 'column'); if (!in_array($width, ['column', 'full', 'bleed'])) $width = 'column'; $imageUrl = ($page && $imageName) ? $page->url() . '/' . $imageName : $imageName; $widthClass = $width !== 'column' ? ' img-caption--' . $width : ''; $captionHtml = ''; if ($caption || $credit) { $creditHtml = $credit ? ' ยท ' . $credit . '' : ''; $captionHtml = '
' . $caption . $creditHtml . '
'; } return << {$alt} {$captionHtml} HTML; }); } }