Skip to content

Commit f080e8b

Browse files
committed
Add support for an alternative screencast directive
1 parent 5bfe60d commit f080e8b

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

src/DocsKernel.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
use Doctrine\RST\ErrorManager;
1616
use Doctrine\RST\Event\PostBuildRenderEvent;
1717
use Doctrine\RST\Event\PreNodeRenderEvent;
18+
use Doctrine\RST\Event\PreParseDocumentEvent;
1819
use Doctrine\RST\Kernel;
20+
use SymfonyDocsBuilder\Listener\AdmonitionListener;
1921
use SymfonyDocsBuilder\Listener\AssetsCopyListener;
2022
use SymfonyDocsBuilder\Listener\CopyImagesListener;
2123

@@ -42,6 +44,11 @@ public function initBuilder(Builder $builder): void
4244

4345
private function initializeListeners(EventManager $eventManager, ErrorManager $errorManager)
4446
{
47+
$eventManager->addEventListener(
48+
PreParseDocumentEvent::PRE_PARSE_DOCUMENT,
49+
new AdmonitionListener()
50+
);
51+
4552
$eventManager->addEventListener(
4653
PreNodeRenderEvent::PRE_NODE_RENDER,
4754
new CopyImagesListener($this->buildConfig, $errorManager)

src/Listener/AdmonitionListener.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Docs Builder package.
7+
* (c) Ryan Weaver <ryan@symfonycasts.com>
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace SymfonyDocsBuilder\Listener;
13+
14+
use Doctrine\RST\Event\PreParseDocumentEvent;
15+
16+
final class AdmonitionListener
17+
{
18+
public function preParseDocument(PreParseDocumentEvent $event)
19+
{
20+
// TODO: remove this temporary fix when Symfony Docs are updated to use the new '.. screencast::' directive
21+
$event->setContents(str_replace('.. admonition:: Screencast', '.. screencast::', $event->getContents()));
22+
}
23+
}

tests/fixtures/expected/blocks/directives/screencast.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,15 @@
99
<a href="https://symfonycasts.com/screencast/symfony" class="reference external" rel="external noopener noreferrer" target="_blank">Stellar Development with Symfony</a>
1010
screencast series.</p>
1111
</div>
12+
13+
<div class="admonition admonition-screencast ">
14+
<p class="admonition-title">
15+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" width="24" height="24" viewbox="0 0 24 24" stroke="currentColor">
16+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"></path>
17+
</svg>
18+
<span>Screencast</span>
19+
</p>
20+
<p>Do you prefer video tutorials? Check out the
21+
<a href="https://symfonycasts.com/screencast/symfony" class="reference external" rel="external noopener noreferrer" target="_blank">Stellar Development with Symfony</a>
22+
screencast series.</p>
23+
</div>

tests/fixtures/source/blocks/directives/screencast.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33
Do you prefer video tutorials? Check out the
44
`Stellar Development with Symfony <https://symfonycasts.com/screencast/symfony>`_
55
screencast series.
6+
7+
.. admonition:: Screencast
8+
9+
Do you prefer video tutorials? Check out the
10+
`Stellar Development with Symfony <https://symfonycasts.com/screencast/symfony>`_
11+
screencast series.

0 commit comments

Comments
 (0)