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

54 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2024-11-19 08:02:04 +01:00
<?php
declare(strict_types=1);
namespace Doctrine\RST\Directives;
use Doctrine\RST\Nodes\Node;
use Doctrine\RST\Parser;
use Doctrine\RST\Toc\GlobSearcher;
use Doctrine\RST\Toc\ToctreeBuilder;
final class Toctree extends Directive
{
/** @var ToctreeBuilder */
private $toctreeBuilder;
public function __construct()
{
$this->toctreeBuilder = new ToctreeBuilder(new GlobSearcher());
}
public function getName(): string
{
return 'toctree';
}
/** @param string[] $options */
public function process(
Parser $parser,
?Node $node,
string $variable,
string $data,
array $options
): void {
if ($node === null) {
return;
}
$environment = $parser->getEnvironment();
$toctreeFiles = $this->toctreeBuilder
->buildToctreeFiles($environment, $node, $options);
foreach ($toctreeFiles as $file) {
$environment->addDependency($file);
}
$tocNode = $parser->getNodeFactory()
->createTocNode($environment, $toctreeFiles, $options);
$parser->getDocument()->addNode($tocNode);
}
}