Skip to content

Commit 9b4452a

Browse files
authored
Merge pull request #960 from phpDocumentor/backport/1.x/pr-954
[1.x] [FEATURE] Introduce noindex option for confvals
2 parents 45c565c + 405ba01 commit 9b4452a

File tree

10 files changed

+173
-3
lines changed

10 files changed

+173
-3
lines changed

packages/guides-restructured-text/resources/template/html/body/directive/confval.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<dl class="confval">
2-
<dt id="{{ node.anchor }}">
2+
<dt {%- if node.isNoindex == false %} id="{{ node.anchor }}"{% endif %}>
33
<code class="sig-name descname"><span class="pre">{{ node.plainContent }}</span></code></dt>
44
<dd>
55
<div class="line-block">

packages/guides-restructured-text/src/RestructuredText/Directives/ConfvalDirective.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ protected function processSub(
8383
$type = $this->inlineParser->parse($directive->getOption('default')->toString(), $blockContext);
8484
}
8585

86+
$noindex = $directive->hasOption('noindex');
87+
8688
foreach ($directive->getOptions() as $option) {
8789
if (in_array($option->getName(), ['type', 'required', 'default', 'noindex', 'name'], true)) {
8890
continue;
@@ -91,6 +93,6 @@ protected function processSub(
9193
$additionalOptions[$option->getName()] = $this->inlineParser->parse($option->toString(), $blockContext);
9294
}
9395

94-
return new ConfvalNode($id, $directive->getData(), $type, $required, $default, $additionalOptions, $collectionNode->getChildren());
96+
return new ConfvalNode($id, $directive->getData(), $type, $required, $default, $additionalOptions, $collectionNode->getChildren(), $noindex);
9597
}
9698
}

packages/guides-restructured-text/src/RestructuredText/Nodes/ConfvalNode.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
use phpDocumentor\Guides\Nodes\CompoundNode;
1717
use phpDocumentor\Guides\Nodes\InlineCompoundNode;
18+
use phpDocumentor\Guides\Nodes\LinkTargetNode;
1819
use phpDocumentor\Guides\Nodes\Node;
20+
use phpDocumentor\Guides\Nodes\OptionalLinkTargetsNode;
1921
use phpDocumentor\Guides\Nodes\PrefixedLinkTargetNode;
2022

2123
/**
@@ -25,7 +27,7 @@
2527
*
2628
* @extends CompoundNode<Node>
2729
*/
28-
final class ConfvalNode extends CompoundNode implements PrefixedLinkTargetNode
30+
final class ConfvalNode extends CompoundNode implements LinkTargetNode, OptionalLinkTargetsNode, PrefixedLinkTargetNode
2931
{
3032
public const LINK_TYPE = 'std:confval';
3133
public const LINK_PREFIX = 'confval-';
@@ -42,6 +44,7 @@ public function __construct(
4244
private readonly InlineCompoundNode|null $default = null,
4345
private readonly array $additionalOptions = [],
4446
array $value = [],
47+
private readonly bool $noindex = false,
4548
) {
4649
parent::__construct($value);
4750
}
@@ -96,4 +99,9 @@ public function getPrefix(): string
9699
{
97100
return self::LINK_PREFIX;
98101
}
102+
103+
public function isNoindex(): bool
104+
{
105+
return $this->noindex;
106+
}
99107
}

packages/guides/src/Compiler/NodeTransformers/CollectLinkTargetsTransformer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use phpDocumentor\Guides\Nodes\LinkTargetNode;
2222
use phpDocumentor\Guides\Nodes\MultipleLinkTargetsNode;
2323
use phpDocumentor\Guides\Nodes\Node;
24+
use phpDocumentor\Guides\Nodes\OptionalLinkTargetsNode;
2425
use phpDocumentor\Guides\Nodes\PrefixedLinkTargetNode;
2526
use phpDocumentor\Guides\Nodes\SectionNode;
2627
use phpDocumentor\Guides\ReferenceResolvers\AnchorNormalizer;
@@ -95,6 +96,10 @@ public function enterNode(Node $node, CompilerContext $compilerContext): Node
9596
}
9697

9798
if ($node instanceof LinkTargetNode) {
99+
if ($node instanceof OptionalLinkTargetsNode && $node->isNoindex()) {
100+
return $node;
101+
}
102+
98103
$currentDocument = $this->documentStack->top();
99104
Assert::notNull($currentDocument);
100105
$anchor = $this->anchorReducer->reduceAnchor($node->getId());
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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\Nodes;
15+
16+
/**
17+
* Makes the implementing node an optional link target. If Noindex is true
18+
* no references are generated, there is no entry in the objects index and no
19+
* warning about duplicate ids.
20+
*
21+
* Used for example in https://sphinx-toolbox.readthedocs.io/en/stable/extensions/confval.html#directive-option-confval-noindex
22+
*/
23+
interface OptionalLinkTargetsNode extends LinkTargetNode
24+
{
25+
public function isNoindex(): bool;
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!-- content start -->
2+
<div class="section" id="confval-directive">
3+
<h1>Confval directive</h1>
4+
<dl class="confval">
5+
<dt>
6+
<code class="sig-name descname"><span class="pre">demo</span></code></dt>
7+
<dd>
8+
<div class="line-block">
9+
<div class="line"><strong>Type:</strong> <code>&quot;Hello World&quot;</code></div>
10+
<div class="line"><strong>Required:</strong> true</div>
11+
<div class="line"><strong>Custom Info:</strong> <strong>custom</strong></div>
12+
13+
</div>
14+
<div class="confval-description">
15+
16+
<p>This is the confval <code>demo</code> content!</p>
17+
18+
<p>Another paragraph.</p>
19+
20+
</div>
21+
</dd>
22+
</dl>
23+
24+
<p>See option <a href="/index.html#confval-demo">demo</a>.</p>
25+
26+
</div>
27+
<!-- content end -->
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!-- content start -->
2+
<div class="section" id="confval-directive">
3+
<h1>Confval directive</h1>
4+
<dl class="confval">
5+
<dt id="confval-demo">
6+
<code class="sig-name descname"><span class="pre">demo</span></code></dt>
7+
<dd>
8+
<div class="line-block">
9+
<div class="line"><strong>Type:</strong> <code>&quot;Hello World&quot;</code></div>
10+
<div class="line"><strong>Required:</strong> true</div>
11+
<div class="line"><strong>Custom Info:</strong> <strong>custom</strong></div>
12+
13+
</div>
14+
<div class="confval-description">
15+
16+
<p>This is the confval <code>demo</code> content!</p>
17+
18+
<p>Another paragraph.</p>
19+
20+
</div>
21+
</dd>
22+
</dl>
23+
24+
<p>See option <a href="/index.html#confval-demo">demo</a>.</p>
25+
26+
<div class="toc">
27+
<ul class="menu-level">
28+
<li class="toc-item">
29+
<a href="/another.html#confval-directive">Confval directive</a>
30+
31+
32+
</li>
33+
</ul>
34+
</div>
35+
</div>
36+
<!-- content end -->
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"std:doc": {
3+
"another": [
4+
"-",
5+
"-",
6+
"another.html",
7+
"Confval directive"
8+
],
9+
"index": [
10+
"-",
11+
"-",
12+
"index.html",
13+
"Confval directive"
14+
]
15+
},
16+
"std:label": {
17+
"confval-directive": [
18+
"-",
19+
"-",
20+
"index.html#confval-directive",
21+
"Confval directive"
22+
]
23+
},
24+
"std:confval": {
25+
"demo": [
26+
"-",
27+
"-",
28+
"index.html#demo",
29+
"demo"
30+
]
31+
}
32+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Confval directive
2+
=================
3+
4+
.. confval:: demo
5+
:type: :php:`string`
6+
:default: ``"Hello World"``
7+
:required: true
8+
:Custom Info: **custom**
9+
:noindex:
10+
11+
This is the confval ``demo`` content!
12+
13+
Another paragraph.
14+
15+
See option :confval:`demo`.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Confval directive
2+
=================
3+
4+
.. confval:: demo
5+
:type: :php:`string`
6+
:default: ``"Hello World"``
7+
:required: true
8+
:Custom Info: **custom**
9+
10+
This is the confval ``demo`` content!
11+
12+
Another paragraph.
13+
14+
See option :confval:`demo`.
15+
16+
.. toctree::
17+
:glob:
18+
19+
*

0 commit comments

Comments
 (0)