Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
->set(ImageDirective::class)
->set(ImportantDirective::class)
->set(IncludeDirective::class)
->arg('$startingRule', service(DocumentRule::class))
->set(IndexDirective::class)
->set(LaTeXMain::class)
->set(LiteralincludeDirective::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use phpDocumentor\Guides\RestructuredText\Nodes\CollectionNode;
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext;
use phpDocumentor\Guides\RestructuredText\Parser\Directive;
use phpDocumentor\Guides\RestructuredText\Parser\Productions\DocumentRule;
use RuntimeException;

use function array_key_exists;
Expand All @@ -28,6 +29,10 @@

final class IncludeDirective extends BaseDirective
{
public function __construct(private readonly DocumentRule $startingRule)
{
}

public function getName(): string
{
return 'include';
Expand All @@ -38,9 +43,7 @@ public function processNode(
BlockContext $blockContext,
Directive $directive,
): Node {
$parser = $blockContext->getDocumentParserContext()->getParser();
$subParser = $parser->getSubParser();
$parserContext = $parser->getParserContext();
$parserContext = $blockContext->getDocumentParserContext()->getParser()->getParserContext();
$path = $parserContext->absoluteRelativePath($directive->getData());

$origin = $parserContext->getOrigin();
Expand Down Expand Up @@ -72,6 +75,13 @@ public function processNode(
return $codeNode;
}

return new CollectionNode($subParser->parse($parser->getParserContext(), $contents)->getChildren());
$currentDocument = $blockContext->getDocumentParserContext()->getDocument();
$subContext = new BlockContext($blockContext->getDocumentParserContext(), $contents);
$document = $this->startingRule->apply($subContext);

//Reset the document, as it was changed by the apply method.
$blockContext->getDocumentParserContext()->setDocument($currentDocument);

return new CollectionNode($document->getChildren());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function applies(BlockContext $blockContext): bool
return $blockContext->getDocumentIterator()->atStart();
}

public function apply(BlockContext $blockContext, CompoundNode|null $on = null): DocumentNode|null
public function apply(BlockContext $blockContext, CompoundNode|null $on = null): DocumentNode
{
Assert::nullOrIsInstanceOf($on, DocumentNode::class);

Expand Down
14 changes: 7 additions & 7 deletions tests/Integration/tests-bootstrap/index/expected/somePage.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
Expand All @@ -20,7 +20,7 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">



<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a href="/anotherPage.html" class="nav-link " >
Expand All @@ -47,7 +47,7 @@
<div class="col-lg-3">
<div class="rubric">Main Menu</div>


<nav class="nav flex-column">
<ul class="level-1">
<li><a href="/anotherPage.html"
Expand All @@ -68,20 +68,20 @@

</div>
<div class="col-lg-9">

<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/index.html">Document Title</a></li>
<li class="breadcrumb-item"><a href="/somePage.html">Some Page</a></li>
</ol>
</nav>



<div class="section" id="some-page">
<h1>Some Page</h1>

<p>Lorem Ipsum Dolor.</p>
<p>Lorem Ipsum <span class="custom">Dolor</span>.</p>
</div>

</div>
Expand All @@ -94,7 +94,7 @@ <h1>Some Page</h1>
<p>Generated by <a href="https://www.phpdoc.org/">phpDocumentor</a>.</p>
</div>
</footer>

<!-- Optional JavaScript; choose one of the two! -->

<!-- Option 1: Bootstrap Bundle with Popper -->
Expand Down
2 changes: 2 additions & 0 deletions tests/Integration/tests-bootstrap/index/input/include.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
:identifier: footer

Generated by `phpDocumentor <https://www.phpdoc.org/>`__.

.. role:: custom
2 changes: 1 addition & 1 deletion tests/Integration/tests-bootstrap/index/input/somePage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
Some Page
=========

Lorem Ipsum Dolor.
Lorem Ipsum :custom:`Dolor`.