gl-website-deployer/vendor/doctrine/rst-parser/lib/LaTeX/Directives/Image.php

46 lines
922 B
PHP
Raw Permalink Normal View History

2024-11-19 08:02:04 +01:00
<?php
declare(strict_types=1);
namespace Doctrine\RST\LaTeX\Directives;
use Doctrine\RST\Directives\Directive;
use Doctrine\RST\Nodes\Node;
use Doctrine\RST\Parser;
use Exception;
use function sprintf;
/**
* Renders an image, example :
*
* .. image:: image.jpg
* :width: 100
* :title: An image
*/
final class Image extends Directive
{
public function getName(): string
{
return 'image';
}
/** @param string[] $options */
public function processNode(
Parser $parser,
string $variable,
string $data,
array $options
): ?Node {
$environment = $parser->getEnvironment();
$url = $environment->relativeUrl($data);
if ($url === null) {
throw new Exception(sprintf('Could not build relative url for %s', $data));
}
return $parser->getNodeFactory()->createImageNode($url, $options);
}
}