Skip to content

Commit 283a9eb

Browse files
committed
[BUGFIX] Warn when a directive has not title
resolves #983
1 parent 9f35276 commit 283a9eb

File tree

5 files changed

+55
-9
lines changed

5 files changed

+55
-9
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
use phpDocumentor\Guides\RestructuredText\Parser\InlineParser;
2323
use phpDocumentor\Guides\RestructuredText\Parser\Productions\Rule;
2424
use phpDocumentor\Guides\RestructuredText\TextRoles\GenericLinkProvider;
25+
use Psr\Log\LoggerInterface;
2526

2627
use function boolval;
2728
use function in_array;
29+
use function trim;
2830

2931
/**
3032
* The confval directive configuration values.
@@ -41,6 +43,7 @@ public function __construct(
4143
GenericLinkProvider $genericLinkProvider,
4244
private readonly AnchorNormalizer $anchorReducer,
4345
private readonly InlineParser $inlineParser,
46+
private readonly LoggerInterface|null $logger = null,
4447
) {
4548
parent::__construct($startingRule);
4649

@@ -71,6 +74,12 @@ protected function processSub(
7174
$required = false;
7275
$default = null;
7376
$additionalOptions = [];
77+
if (trim($directive->getData()) === '') {
78+
if ($this->logger !== null) {
79+
$this->logger->warning('A directive must have a title: .. confval:: [some_title]', $blockContext->getLoggerInformation());
80+
}
81+
}
82+
7483
if ($directive->hasOption('type')) {
7584
$type = $this->inlineParser->parse($directive->getOption('type')->toString(), $blockContext);
7685
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!-- content start -->
2+
<div class="section" id="confval-directive">
3+
<h1>Confval directive</h1>
4+
<dl class="confval">
5+
<dt id="confval-">
6+
<code class="sig-name descname"><span class="pre"></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+
</div>
24+
<!-- content end -->
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
app.WARNING: A directive must have a title
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Confval directive
2+
=================
3+
4+
.. confval::
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.
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<!-- content start -->
2-
<div class="section" id="uml-directive">
3-
<h1>Uml Directive</h1>
4-
<figure
5-
class="uml-diagram"
6-
style="width: 1000" ><figcaption>Figure 1-1: Application flow</figcaption></figure>
7-
<figure
8-
class="uml-diagram"
9-
style="width: 1000" ><figcaption>Figure 1-1: Application flow</figcaption></figure>
10-
</div>
2+
<div class="section" id="uml-directive">
3+
<h1>Uml Directive</h1>
4+
<figure
5+
class="uml-diagram"
6+
style="width: 1000" ><figcaption>Figure 1-1: Application flow</figcaption></figure>
7+
<figure
8+
class="uml-diagram"
9+
style="width: 1000" ><figcaption>Figure 1-1: Application flow</figcaption></figure>
10+
</div>
1111
<!-- content end -->

0 commit comments

Comments
 (0)