feat: add pull-quote and snap-gallery shortcodes

This commit is contained in:
2026-06-19 22:50:27 +02:00
parent 3b5dc18ec6
commit fcdb3de387
2 changed files with 97 additions and 0 deletions
@@ -0,0 +1,43 @@
<?php
namespace Grav\Plugin\Shortcodes;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
class PullQuoteShortcode extends Shortcode
{
public function init(): void
{
$this->shortcode->getHandlers()->add('pull-quote', function (ShortcodeInterface $sc) {
$plugin = $this->grav['plugins']->getPlugin('story-blocks');
$page = $plugin ? $plugin->getCurrentPage() : null;
$imageName = $sc->getParameter('image', '');
$alt = htmlspecialchars($sc->getParameter('alt', ''), ENT_QUOTES);
$content = trim($sc->getContent());
$imageUrl = ($page && $imageName) ? $page->url() . '/' . $imageName : '';
$bgHtml = '';
if ($imageUrl) {
$bgHtml = <<<HTML
<div class="pull-quote__bg" aria-hidden="true">
<img src="{$imageUrl}" alt="{$alt}" class="pull-quote__bg-img" loading="lazy">
<div class="pull-quote__bg-tint"></div>
</div>
HTML;
}
$innerClass = $imageUrl ? 'pull-quote__inner' : 'pull-quote__inner pull-quote__inner--no-image';
return <<<HTML
<blockquote class="pull-quote" aria-label="Pull quote">
{$bgHtml}
<div class="{$innerClass}">
<span class="pull-quote__mark" aria-hidden="true">"</span>
<p class="pull-quote__text">{$content}</p>
<span class="pull-quote__mark pull-quote__mark--close" aria-hidden="true">"</span>
</div>
</blockquote>
HTML;
});
}
}