|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Docs Builder package. |
| 5 | + * (c) Ryan Weaver <[email protected]> |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +namespace SymfonyDocsBuilder\Directive; |
| 11 | + |
| 12 | +use Doctrine\RST\Directives\SubDirective; |
| 13 | +use Doctrine\RST\Nodes\Node; |
| 14 | +use Doctrine\RST\Parser; |
| 15 | + |
| 16 | +/** |
| 17 | + * Overridden to handle "figclass" properly. |
| 18 | + */ |
| 19 | +class FigureDirective extends SubDirective |
| 20 | +{ |
| 21 | + public function getName(): string |
| 22 | + { |
| 23 | + return 'figure'; |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @param string[] $options |
| 28 | + */ |
| 29 | + public function processSub( |
| 30 | + Parser $parser, |
| 31 | + ?Node $document, |
| 32 | + string $variable, |
| 33 | + string $data, |
| 34 | + array $options |
| 35 | + ): ?Node { |
| 36 | + $environment = $parser->getEnvironment(); |
| 37 | + |
| 38 | + $url = $environment->relativeUrl($data); |
| 39 | + |
| 40 | + if ($url === null) { |
| 41 | + throw new \Exception(sprintf('Could not get relative url for %s', $data)); |
| 42 | + } |
| 43 | + |
| 44 | + $nodeFactory = $parser->getNodeFactory(); |
| 45 | + |
| 46 | + /* Start Custom Code */ |
| 47 | + $figClass = $options['figclass'] ?? null; |
| 48 | + unset($options['figclass']); |
| 49 | + /* End Custom Code */ |
| 50 | + |
| 51 | + $figureNode = $parser->getNodeFactory()->createFigureNode( |
| 52 | + $nodeFactory->createImageNode($url, $options), |
| 53 | + $document |
| 54 | + ); |
| 55 | + |
| 56 | + /* Start Custom Code */ |
| 57 | + if ($figClass) { |
| 58 | + $figureNode->setClasses(explode(' ', $figClass)); |
| 59 | + } |
| 60 | + /* End Custom Code */ |
| 61 | + |
| 62 | + return $figureNode; |
| 63 | + } |
| 64 | +} |
0 commit comments