Skip to content

Commit d4af3bd

Browse files
authored
Merge pull request #462 from linawolf/titled-admonitions
Support titled and not titled admonitions
2 parents 8bf9af9 + bc1f6d1 commit d4af3bd

File tree

9 files changed

+38
-22
lines changed

9 files changed

+38
-22
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ final protected function processSub(
3434
): Node|null {
3535
return new AdmonitionNode(
3636
$this->name,
37+
$directive->getDataNode(),
3738
$this->text,
3839
$document->getChildren(),
3940
);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ protected function processSub(DocumentNode $document, Directive $directive): Nod
5353

5454
return new AdmonitionNode(
5555
$name,
56+
$directive->getDataNode(),
5657
$directive->getData(),
5758
$document->getChildren(),
59+
true,
5860
);
5961
}
6062
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function render(Node $node, RenderContext $renderContext): string
4848
[
4949
'name' => $node->getName(),
5050
'text' => $node->getText(),
51+
'title' => $node->getTitle(),
52+
'isTitled' => $node->isTitled(),
5153
'class' => implode(' ', $classes),
5254
'node' => $node->getValue(),
5355
],

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
namespace phpDocumentor\Guides\RestructuredText\Nodes;
1515

1616
use phpDocumentor\Guides\Nodes\CompoundNode;
17+
use phpDocumentor\Guides\Nodes\InlineCompoundNode;
1718
use phpDocumentor\Guides\Nodes\Node;
1819

1920
/** @extends CompoundNode<Node> */
2021
class AdmonitionNode extends CompoundNode
2122
{
22-
/** {@inheritDoc} */
23-
public function __construct(private readonly string $name, private readonly string $text, array $value)
23+
/** @param Node[] $value */
24+
public function __construct(private readonly string $name, private readonly InlineCompoundNode|null $title, private readonly string $text, array $value, private readonly bool $isTitled = false)
2425
{
2526
parent::__construct($value);
2627
}
@@ -30,8 +31,18 @@ public function getName(): string
3031
return $this->name;
3132
}
3233

34+
public function getTitle(): InlineCompoundNode|null
35+
{
36+
return $this->title;
37+
}
38+
3339
public function getText(): string
3440
{
3541
return $this->text;
3642
}
43+
44+
public function isTitled(): bool
45+
{
46+
return $this->isTitled;
47+
}
3748
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<div class="admonition {{ name }}{{ class ? (' '~class) }}{% if node.classes %} {{ node.classesString }}{% endif %}">
2-
{% if title %}<p class="admonition-title">{{ title }}</p>{% endif %}
2+
{% if title and isTitled %}<p class="admonition-title">{{ renderNode(title) }}</p>{% endif %}
3+
{% if title and not isTitled %}<p>{{ renderNode(title) }}</p>{% endif %}
34
{{ renderNode(node) }}
45
</div>
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
SKIP contents of admonitions must start after the directive indicator (https://docutils.sourceforge.io/docs/ref/rst/directives.html#admonitions)
21
<p>Testing various supported formats:</p>
3-
<div class="phpdocumentor-admonition note">
4-
<svg class="phpdocumentor-admonition__icon" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
5-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"></path>
6-
</svg>
7-
<article>
8-
<p>This is the first line of content</p>
9-
<p>And this is the second line</p>
10-
</article>
2+
<div class="admonition this-is-the-title">
3+
<p class="admonition-title">This is the title</p>
4+
<p>And this is the second line</p>
115
</div>
12-
<div class="phpdocumentor-admonition note">
13-
<svg class="phpdocumentor-admonition__icon" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
14-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"></path>
15-
</svg>
16-
<article>
17-
<p>This is the first line of content</p>
18-
</article>
6+
<div class="admonition note">
7+
<p>This is the first line of content</p>
8+
<p>And this is the second line</p>
9+
</div>
10+
<div class="admonition note">
11+
<p>This is the first line of content</p>
1912
</div>

tests/Functional/tests/admonitions-contents/admonitions-contents.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Testing various supported formats:
22

3+
.. admonition:: This is the title
4+
5+
And this is the second line
6+
37
.. note:: This is the first line of content
48

59
And this is the second line
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<div class="admonition screencast">
2+
<p class="admonition-title">Screencast</p>
23
<p>Enjoy a screencast better? Watch this video: ...</p>
34
</div>

tests/Integration/tests/class-directive/expected/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<title></title>
4+
<title></title>
5+
56
</head>
67
<body>
78
<p class="special-paragraph2">Test special-paragraph 1.</p><p class="special-paragraph2">Test special-paragraph 2.</p>
@@ -15,11 +16,11 @@
1516

1617

1718
<div class="admonition note my-class">
18-
19+
<p>A Note with a class</p>
1920
</div>
2021

2122
<div class="admonition note">
22-
23+
<p>A note without a class</p>
2324
</div>
2425

2526
<blockquote class="highlights"><p>Block quote text.</p></blockquote>

0 commit comments

Comments
 (0)