diff --git a/packages/guides-restructured-text/src/RestructuredText/Directives/ContentsDirective.php b/packages/guides-restructured-text/src/RestructuredText/Directives/ContentsDirective.php index 7bd61ebe2..25865a484 100644 --- a/packages/guides-restructured-text/src/RestructuredText/Directives/ContentsDirective.php +++ b/packages/guides-restructured-text/src/RestructuredText/Directives/ContentsDirective.php @@ -39,6 +39,7 @@ public function process( ); return (new ContentMenuNode([$absoluteUrl])) - ->withOptions($this->optionsToArray($options)); + ->withOptions($this->optionsToArray($options)) + ->withCaption($directive->getDataNode()); } } diff --git a/packages/guides/resources/template/html/body/menu/content-menu.html.twig b/packages/guides/resources/template/html/body/menu/content-menu.html.twig index fba2c51f9..64a208d4a 100644 --- a/packages/guides/resources/template/html/body/menu/content-menu.html.twig +++ b/packages/guides/resources/template/html/body/menu/content-menu.html.twig @@ -1,5 +1,8 @@ {% apply spaceless %}
+ {% if node.caption %} +

{{ renderNode(node.caption) }}

+ {% endif %} {% include "body/menu/menu-level.html.twig" %}
{% endapply %} diff --git a/packages/guides/src/Nodes/Menu/ContentMenuNode.php b/packages/guides/src/Nodes/Menu/ContentMenuNode.php index a0e9f1b7f..ae791b9e2 100644 --- a/packages/guides/src/Nodes/Menu/ContentMenuNode.php +++ b/packages/guides/src/Nodes/Menu/ContentMenuNode.php @@ -13,11 +13,15 @@ namespace phpDocumentor\Guides\Nodes\Menu; +use phpDocumentor\Guides\Nodes\InlineCompoundNode; + use function is_scalar; /** @link https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#table-of-contents */ class ContentMenuNode extends MenuNode { + private InlineCompoundNode|null $caption; + public function getDepth(): int { if ($this->hasOption('depth') && is_scalar($this->getOption('depth'))) { @@ -31,4 +35,17 @@ public function isPageLevelOnly(): bool { return false; } + + public function getCaption(): InlineCompoundNode|null + { + return $this->caption; + } + + public function withCaption(InlineCompoundNode|null $caption): ContentMenuNode + { + $that = clone $this; + $that->caption = $caption; + + return $that; + } } diff --git a/tests/Integration/tests/navigation/contents/expected/contents-with-title.html b/tests/Integration/tests/navigation/contents/expected/contents-with-title.html index 7da65808c..7a3e6f66f 100644 --- a/tests/Integration/tests/navigation/contents/expected/contents-with-title.html +++ b/tests/Integration/tests/navigation/contents/expected/contents-with-title.html @@ -2,7 +2,7 @@

Title

-
+

Table of Content

Depth Level 1

diff --git a/tests/Integration/tests/navigation/contents/input/contents-with-title.rst b/tests/Integration/tests/navigation/contents/input/contents-with-title.rst index 863dbe8e6..ec2012516 100644 --- a/tests/Integration/tests/navigation/contents/input/contents-with-title.rst +++ b/tests/Integration/tests/navigation/contents/input/contents-with-title.rst @@ -1,7 +1,7 @@ Title ===== -.. contents:: Table of Content +.. contents:: **Table of Content** Depth Level 1 -------------