Skip to content

Commit 17a3997

Browse files
linawolfjaapio
authored andcommitted
[FEATURE] Support automatically created multi-level menus
Resolves #1108
1 parent b1200a1 commit 17a3997

File tree

5 files changed

+81
-45
lines changed

5 files changed

+81
-45
lines changed

packages/guides-markdown/src/Markdown/Parsers/BlockQuoteParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public function parse(MarkupLanguageParser $parser, NodeWalker $walker, CommonMa
6262

6363
// leaving the heading node
6464
if ($commonMarkNode instanceof BlockQuote) {
65-
if (count($content) > 0 and $content[0] instanceof ParagraphNode and ($content[0]->getValue()[0]) instanceof InlineCompoundNode) {
65+
if (count($content) > 0 && $content[0] instanceof ParagraphNode && ($content[0]->getValue()[0]) instanceof InlineCompoundNode) {
6666
$paragraphContent = $content[0]->getValue()[0]->getValue();
67-
if (count($paragraphContent) > 0 and $paragraphContent[0] instanceof PlainTextInlineNode) {
67+
if (count($paragraphContent) > 0 && $paragraphContent[0] instanceof PlainTextInlineNode) {
6868
$text = trim($paragraphContent[0]->getValue());
6969
$newParagraphContent = $paragraphContent;
7070
array_shift($newParagraphContent);

packages/guides-restructured-text/src/RestructuredText/NodeRenderers/Html/AdmonitionNodeRenderer.php

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,6 @@
1313

1414
namespace phpDocumentor\Guides\RestructuredText\NodeRenderers\Html;
1515

16-
use InvalidArgumentException;
17-
use phpDocumentor\Guides\NodeRenderers\NodeRenderer;
18-
use phpDocumentor\Guides\Nodes\AdmonitionNode;
19-
use phpDocumentor\Guides\Nodes\Node;
20-
use phpDocumentor\Guides\RenderContext;
21-
use phpDocumentor\Guides\TemplateRenderer;
22-
23-
use function implode;
24-
use function is_a;
25-
26-
/** @implements NodeRenderer<AdmonitionNode> */
27-
final class AdmonitionNodeRenderer implements NodeRenderer
16+
final class AdmonitionNodeRenderer extends \phpDocumentor\Guides\NodeRenderers\Html\AdmonitionNodeRenderer
2817
{
29-
public function __construct(private readonly TemplateRenderer $renderer)
30-
{
31-
}
32-
33-
public function supports(string $nodeFqcn): bool
34-
{
35-
return $nodeFqcn === AdmonitionNode::class || is_a($nodeFqcn, AdmonitionNode::class, true);
36-
}
37-
38-
public function render(Node $node, RenderContext $renderContext): string
39-
{
40-
if ($node instanceof AdmonitionNode === false) {
41-
throw new InvalidArgumentException('Node must be an instance of ' . AdmonitionNode::class);
42-
}
43-
44-
$classes = $node->getClasses();
45-
46-
return $this->renderer->renderTemplate(
47-
$renderContext,
48-
'body/admonition.html.twig',
49-
[
50-
'name' => $node->getName(),
51-
'text' => $node->getText(),
52-
'title' => $node->getTitle(),
53-
'isTitled' => $node->isTitled(),
54-
'class' => implode(' ', $classes),
55-
'node' => $node->getValue(),
56-
],
57-
);
58-
}
5918
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link https://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Guides\RestructuredText\Nodes;
15+
16+
class AdmonitionNode extends \phpDocumentor\Guides\Nodes\AdmonitionNode
17+
{
18+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link https://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Guides\NodeRenderers\Html;
15+
16+
use InvalidArgumentException;
17+
use phpDocumentor\Guides\NodeRenderers\NodeRenderer;
18+
use phpDocumentor\Guides\Nodes\AdmonitionNode;
19+
use phpDocumentor\Guides\Nodes\Node;
20+
use phpDocumentor\Guides\RenderContext;
21+
use phpDocumentor\Guides\TemplateRenderer;
22+
23+
use function implode;
24+
use function is_a;
25+
26+
/** @implements NodeRenderer<AdmonitionNode> */
27+
class AdmonitionNodeRenderer implements NodeRenderer
28+
{
29+
public function __construct(private readonly TemplateRenderer $renderer)
30+
{
31+
}
32+
33+
public function supports(string $nodeFqcn): bool
34+
{
35+
return $nodeFqcn === AdmonitionNode::class || is_a($nodeFqcn, AdmonitionNode::class, true);
36+
}
37+
38+
public function render(Node $node, RenderContext $renderContext): string
39+
{
40+
if ($node instanceof AdmonitionNode === false) {
41+
throw new InvalidArgumentException('Node must be an instance of ' . AdmonitionNode::class);
42+
}
43+
44+
$classes = $node->getClasses();
45+
46+
return $this->renderer->renderTemplate(
47+
$renderContext,
48+
'body/admonition.html.twig',
49+
[
50+
'name' => $node->getName(),
51+
'text' => $node->getText(),
52+
'title' => $node->getTitle(),
53+
'isTitled' => $node->isTitled(),
54+
'class' => implode(' ', $classes),
55+
'node' => $node->getValue(),
56+
],
57+
);
58+
}
59+
}

packages/guides/src/Nodes/AdmonitionNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace phpDocumentor\Guides\Nodes;
1515

1616
/** @extends CompoundNode<Node> */
17-
final class AdmonitionNode extends CompoundNode
17+
class AdmonitionNode extends CompoundNode
1818
{
1919
/** @param Node[] $value */
2020
public function __construct(private readonly string $name, private readonly InlineCompoundNode|null $title, private readonly string $text, array $value, private readonly bool $isTitled = false)

0 commit comments

Comments
 (0)