Skip to content

Commit 3f74d25

Browse files
committed
[TASK] Make id of confval configurable
releases: main, 1.0
1 parent 81ffdf0 commit 3f74d25

File tree

13 files changed

+284
-5
lines changed

13 files changed

+284
-5
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ protected function processSub(
6161
CollectionNode $collectionNode,
6262
Directive $directive,
6363
): Node|null {
64-
$id = $this->anchorReducer->reduceAnchor($directive->getData());
64+
$id = $directive->getData();
65+
if ($directive->hasOption('name')) {
66+
$id = (string) $directive->getOption('name')->getValue();
67+
}
68+
69+
$id = $this->anchorReducer->reduceAnchor($id);
6570
$type = null;
6671
$required = false;
6772
$default = null;
@@ -79,7 +84,7 @@ protected function processSub(
7984
}
8085

8186
foreach ($directive->getOptions() as $option) {
82-
if (in_array($option->getName(), ['type', 'required', 'default', 'noindex'], true)) {
87+
if (in_array($option->getName(), ['type', 'required', 'default', 'noindex', 'name', 'class'], true)) {
8388
continue;
8489
}
8590

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class ConfvalNode extends CompoundNode implements PrefixedLinkTargetNode
3535
* @param array<string, InlineCompoundNode> $additionalOptions
3636
*/
3737
public function __construct(
38-
private readonly string $id,
38+
private string $id,
3939
private readonly string $plainContent,
4040
private readonly InlineCompoundNode|null $type = null,
4141
private readonly bool $required = false,
@@ -96,4 +96,13 @@ public function getPrefix(): string
9696
{
9797
return self::LINK_PREFIX;
9898
}
99+
100+
/** @return static */
101+
public function withName(string $name): Node
102+
{
103+
$result = clone $this;
104+
$result->id = $name;
105+
106+
return $result;
107+
}
99108
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Another Confval directive</title>
5+
6+
</head>
7+
<body>
8+
<!-- content start -->
9+
<div class="section" id="another-confval-directive">
10+
<a id="another-demo"></a>
11+
<h1>Another Confval directive</h1>
12+
13+
<dl class="confval">
14+
<dt id="confval-another-demo">
15+
<code class="sig-name descname"><span class="pre">demo</span></code></dt>
16+
<dd>
17+
<div class="line-block">
18+
<div class="line"><strong>Type:</strong> <code>&quot;Hello World&quot;</code></div>
19+
<div class="line"><strong>Required:</strong> true</div>
20+
<div class="line"><strong>Custom Info:</strong> <strong>custom</strong></div>
21+
22+
</div>
23+
<div class="confval-description">
24+
<p>This is the confval <code>demo</code> content! It is related to <a href="/index.html#confval-demo">demo</a>.</p><p>Another paragraph.</p>
25+
</div>
26+
</dd>
27+
</dl>
28+
<p>See option <a href="/anotherPage.html#confval-another-demo">demo</a>. We can also link the
29+
headline: <a href="/anotherPage.html#another-demo">Another Confval directive</a>.</p>
30+
</div>
31+
32+
<!-- content end -->
33+
</body>
34+
</html>

tests/Integration/tests/confval/expected/index.html renamed to tests/Integration/tests/confval/confval-samename/expected/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Confval directive</title>
5+
6+
</head>
7+
<body>
18
<!-- content start -->
29
<div class="section" id="confval-directive">
310
<a id="demo"></a>
@@ -20,6 +27,15 @@ <h1>Confval directive</h1>
2027
</dl>
2128
<p>See option <a href="/index.html#confval-demo">demo</a>. We can also link the
2229
headline: <a href="/index.html#demo">Confval directive</a>.</p>
30+
<div class="toc">
31+
<ul class="menu-level">
32+
<li class="toc-item"><a href="/anotherPage.html#another-confval-directive">Another Confval directive</a></li>
33+
34+
</ul>
35+
</div>
36+
2337
</div>
2438

2539
<!-- content end -->
40+
</body>
41+
</html>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"std:doc": {
3+
"anotherPage": [
4+
"-",
5+
"-",
6+
"anotherPage.html",
7+
"Another Confval directive"
8+
],
9+
"index": [
10+
"-",
11+
"-",
12+
"index.html",
13+
"Confval directive"
14+
]
15+
},
16+
"std:label": {
17+
"another-confval-directive": [
18+
"-",
19+
"-",
20+
"anotherPage.html#another-confval-directive",
21+
"Another Confval directive"
22+
],
23+
"another-demo": [
24+
"-",
25+
"-",
26+
"anotherPage.html#another-demo",
27+
"Another Confval directive"
28+
],
29+
"confval-directive": [
30+
"-",
31+
"-",
32+
"index.html#confval-directive",
33+
"Confval directive"
34+
],
35+
"demo": [
36+
"-",
37+
"-",
38+
"index.html#demo",
39+
"Confval directive"
40+
]
41+
},
42+
"std:confval": {
43+
"another-demo": [
44+
"-",
45+
"-",
46+
"anotherPage.html#another-demo",
47+
"demo"
48+
],
49+
"demo": [
50+
"-",
51+
"-",
52+
"index.html#demo",
53+
"demo"
54+
]
55+
}
56+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
.. _another-demo:
3+
4+
Another Confval directive
5+
=========================
6+
7+
.. confval:: demo
8+
:name: another-demo
9+
:type: :php:`string`
10+
:default: ``"Hello World"``
11+
:required: true
12+
:Custom Info: **custom**
13+
14+
This is the confval ``demo`` content! It is related to :confval:`demo`.
15+
16+
Another paragraph.
17+
18+
See option :confval:`another-demo`. We can also link the
19+
headline: :ref:`another-demo`.

tests/Integration/tests/confval/input/index.rst renamed to tests/Integration/tests/confval/confval-samename/input/index.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ Confval directive
1515
Another paragraph.
1616

1717
See option :confval:`demo`. We can also link the
18-
headline: :ref:`demo`.
18+
headline: :ref:`demo`.
19+
20+
.. toctree::
21+
:glob:
22+
23+
*
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Another Confval directive</title>
5+
6+
</head>
7+
<body>
8+
<!-- content start -->
9+
<div class="section" id="another-confval-directive">
10+
<a id="another-demo"></a>
11+
<h1>Another Confval directive</h1>
12+
13+
<dl class="confval">
14+
<dt id="confval-demo">
15+
<code class="sig-name descname"><span class="pre">demo</span></code></dt>
16+
<dd>
17+
<div class="line-block">
18+
<div class="line"><strong>Type:</strong> <code>&quot;Hello World&quot;</code></div>
19+
<div class="line"><strong>Required:</strong> true</div>
20+
<div class="line"><strong>Custom Info:</strong> <strong>custom</strong></div>
21+
22+
</div>
23+
<div class="confval-description">
24+
<p>This is the confval <code>demo</code> content! It is related to <a href="/anotherPage.html#confval-demo">demo</a>.</p><p>Another paragraph.</p>
25+
</div>
26+
</dd>
27+
</dl>
28+
<p>See option <a href="/anotherPage.html#confval-demo">demo</a>. We can also link the
29+
headline: <a href="/anotherPage.html#another-demo">Another Confval directive</a>.</p>
30+
</div>
31+
32+
<!-- content end -->
33+
</body>
34+
</html>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Confval directive</title>
5+
6+
</head>
7+
<body>
8+
<!-- content start -->
9+
<div class="section" id="confval-directive">
10+
<a id="demo"></a>
11+
<h1>Confval directive</h1>
12+
13+
<dl class="confval">
14+
<dt id="confval-demo">
15+
<code class="sig-name descname"><span class="pre">demo</span></code></dt>
16+
<dd>
17+
<div class="line-block">
18+
<div class="line"><strong>Type:</strong> <code>&quot;Hello World&quot;</code></div>
19+
<div class="line"><strong>Required:</strong> true</div>
20+
<div class="line"><strong>Custom Info:</strong> <strong>custom</strong></div>
21+
22+
</div>
23+
<div class="confval-description">
24+
<p>This is the confval <code>demo</code> content!</p><p>Another paragraph.</p>
25+
</div>
26+
</dd>
27+
</dl>
28+
<p>See option <a href="/anotherPage.html#confval-demo">demo</a>. We can also link the
29+
headline: <a href="/index.html#demo">Confval directive</a>.</p>
30+
<div class="toc">
31+
<ul class="menu-level">
32+
<li class="toc-item"><a href="/anotherPage.html#another-confval-directive">Another Confval directive</a></li>
33+
34+
</ul>
35+
</div>
36+
37+
</div>
38+
39+
<!-- content end -->
40+
</body>
41+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
app.WARNING: Duplicate anchor "demo" for link type "std:confval" in document "index". The anchor is already used at "anotherPage"

tests/Integration/tests/confval/expected/objects.inv.json renamed to tests/Integration/tests/confval/confval-warning/expected/objects.inv.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
22
"std:doc": {
3+
"anotherPage": [
4+
"-",
5+
"-",
6+
"anotherPage.html",
7+
"Another Confval directive"
8+
],
39
"index": [
410
"-",
511
"-",
@@ -8,6 +14,18 @@
814
]
915
},
1016
"std:label": {
17+
"another-confval-directive": [
18+
"-",
19+
"-",
20+
"anotherPage.html#another-confval-directive",
21+
"Another Confval directive"
22+
],
23+
"another-demo": [
24+
"-",
25+
"-",
26+
"anotherPage.html#another-demo",
27+
"Another Confval directive"
28+
],
1129
"confval-directive": [
1230
"-",
1331
"-",
@@ -25,7 +43,7 @@
2543
"demo": [
2644
"-",
2745
"-",
28-
"index.html#demo",
46+
"anotherPage.html#demo",
2947
"demo"
3048
]
3149
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
.. _another-demo:
3+
4+
Another Confval directive
5+
=========================
6+
7+
.. confval:: demo
8+
:type: :php:`string`
9+
:default: ``"Hello World"``
10+
:required: true
11+
:Custom Info: **custom**
12+
13+
This is the confval ``demo`` content! It is related to :confval:`demo`.
14+
15+
Another paragraph.
16+
17+
See option :confval:`demo`. We can also link the
18+
headline: :ref:`another-demo`.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
.. _demo:
3+
4+
Confval directive
5+
=================
6+
7+
.. confval:: demo
8+
:type: :php:`string`
9+
:default: ``"Hello World"``
10+
:required: true
11+
:Custom Info: **custom**
12+
13+
This is the confval ``demo`` content!
14+
15+
Another paragraph.
16+
17+
See option :confval:`demo`. We can also link the
18+
headline: :ref:`demo`.
19+
20+
.. toctree::
21+
:glob:
22+
23+
*

0 commit comments

Comments
 (0)