Skip to content

Commit bc539ae

Browse files
committed
1 parent 5ad233a commit bc539ae

File tree

16 files changed

+153
-37
lines changed

16 files changed

+153
-37
lines changed

packages/guides-markdown/src/Markdown/Parsers/BlockQuoteParser.php

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,21 @@
1818
use League\CommonMark\Node\NodeWalker;
1919
use League\CommonMark\Node\NodeWalkerEvent;
2020
use phpDocumentor\Guides\MarkupLanguageParser;
21+
use phpDocumentor\Guides\Nodes\AdmonitionNode;
22+
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
23+
use phpDocumentor\Guides\Nodes\InlineCompoundNode;
2124
use phpDocumentor\Guides\Nodes\Node;
25+
use phpDocumentor\Guides\Nodes\ParagraphNode;
2226
use phpDocumentor\Guides\Nodes\QuoteNode;
2327
use Psr\Log\LoggerInterface;
2428
use RuntimeException;
2529

30+
use function array_shift;
31+
use function count;
2632
use function sprintf;
33+
use function trim;
2734

28-
/** @extends AbstractBlockParser<QuoteNode> */
35+
/** @extends AbstractBlockParser<Node> */
2936
final class BlockQuoteParser extends AbstractBlockParser
3037
{
3138
/** @param iterable<AbstractBlockParser<Node>> $subParsers */
@@ -35,7 +42,7 @@ public function __construct(
3542
) {
3643
}
3744

38-
public function parse(MarkupLanguageParser $parser, NodeWalker $walker, CommonMarkNode $current): QuoteNode
45+
public function parse(MarkupLanguageParser $parser, NodeWalker $walker, CommonMarkNode $current): Node
3946
{
4047
$content = [];
4148

@@ -55,6 +62,58 @@ public function parse(MarkupLanguageParser $parser, NodeWalker $walker, CommonMa
5562

5663
// leaving the heading node
5764
if ($commonMarkNode instanceof BlockQuote) {
65+
if (count($content) > 0 and $content[0] instanceof ParagraphNode and ($content[0]->getValue()[0]) instanceof InlineCompoundNode) {
66+
$paragraphContent = $content[0]->getValue()[0]->getValue();
67+
if (count($paragraphContent) > 0 and $paragraphContent[0] instanceof PlainTextInlineNode) {
68+
$text = trim($paragraphContent[0]->getValue());
69+
$newParagraphContent = $paragraphContent;
70+
array_shift($newParagraphContent);
71+
switch ($text) {
72+
case '[!NOTE]':
73+
return new AdmonitionNode(
74+
'note',
75+
new InlineCompoundNode([new PlainTextInlineNode('Note')]),
76+
'Note',
77+
$newParagraphContent,
78+
);
79+
80+
case '[!TIP]':
81+
return new AdmonitionNode(
82+
'tip',
83+
new InlineCompoundNode([new PlainTextInlineNode('Tip')]),
84+
'Tip',
85+
$newParagraphContent,
86+
);
87+
88+
case '[!IMPORTANT]':
89+
return new AdmonitionNode(
90+
'important',
91+
new InlineCompoundNode([new PlainTextInlineNode('Important')]),
92+
'Important',
93+
$newParagraphContent,
94+
);
95+
96+
case '[!WARNING]':
97+
return new AdmonitionNode(
98+
'warning',
99+
new InlineCompoundNode([new PlainTextInlineNode('Warning')]),
100+
'Warning',
101+
$newParagraphContent,
102+
);
103+
104+
case '[!CAUTION]':
105+
return new AdmonitionNode(
106+
'caution',
107+
new InlineCompoundNode([new PlainTextInlineNode('Caution')]),
108+
'Caution',
109+
$newParagraphContent,
110+
);
111+
}
112+
}
113+
114+
$content[0] = new ParagraphNode([new InlineCompoundNode($paragraphContent)]);
115+
}
116+
58117
return new QuoteNode($content);
59118
}
60119

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
namespace phpDocumentor\Guides\RestructuredText\Directives;
1515

16+
use phpDocumentor\Guides\Nodes\AdmonitionNode;
1617
use phpDocumentor\Guides\Nodes\CollectionNode;
1718
use phpDocumentor\Guides\Nodes\Node;
18-
use phpDocumentor\Guides\RestructuredText\Nodes\AdmonitionNode;
1919
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext;
2020
use phpDocumentor\Guides\RestructuredText\Parser\Directive;
2121
use phpDocumentor\Guides\RestructuredText\Parser\Productions\Rule;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
namespace phpDocumentor\Guides\RestructuredText\Directives;
1515

16+
use phpDocumentor\Guides\Nodes\AdmonitionNode;
1617
use phpDocumentor\Guides\Nodes\CollectionNode;
1718
use phpDocumentor\Guides\Nodes\Node;
18-
use phpDocumentor\Guides\RestructuredText\Nodes\AdmonitionNode;
1919
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext;
2020
use phpDocumentor\Guides\RestructuredText\Parser\Directive;
2121

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

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

1616
use InvalidArgumentException;
1717
use phpDocumentor\Guides\NodeRenderers\NodeRenderer;
18+
use phpDocumentor\Guides\Nodes\AdmonitionNode;
1819
use phpDocumentor\Guides\Nodes\Node;
1920
use phpDocumentor\Guides\RenderContext;
20-
use phpDocumentor\Guides\RestructuredText\Nodes\AdmonitionNode;
2121
use phpDocumentor\Guides\TemplateRenderer;
2222

2323
use function implode;

packages/guides-theme-bootstrap/resources/template/body/admonition.html.twig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
1+
{% if name == 'caution' %}
2+
{% include "body/admonitions/caution.html.twig" %}
3+
{% endif %}
24
{% if name == 'important' %}
35
{% include "body/admonitions/important.html.twig" %}
46
{% endif %}
57
{% if name == 'note' %}
68
{% include "body/admonitions/note.html.twig" %}
79
{% endif %}
8-
{% if name == 'warning' or name == 'caution' %}
10+
{% if name == 'warning' %}
911
{% include "body/admonitions/warning.html.twig" %}
1012
{% endif %}
1113
{% if name == 'tip' or name == 'hint' %}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div class="alert alert-danger {{ class ? (' '~class) }}{% if node.classes %} {{ node.classesString }}{% endif %}" role="alert">
2+
<h4 class="alert-heading">Caution</h4>
3+
{{ renderNode(node) }}
4+
</div>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="alert alert-danger {{ class ? (' '~class) }}{% if node.classes %} {{ node.classesString }}{% endif %}" role="alert">
2-
<h4 class="alert-heading">Tip</h4>
1+
<div class="alert alert-warning {{ class ? (' '~class) }}{% if node.classes %} {{ node.classesString }}{% endif %}" role="alert">
2+
<h4 class="alert-heading">Imortant</h4>
33
{{ renderNode(node) }}
44
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div class="alert alert-danger {{ class ? (' '~class) }}{% if node.classes %} {{ node.classesString }}{% endif %}" role="alert">
2-
<h4 class="alert-heading">Tip</h4>
2+
<h4 class="alert-heading">Warning</h4>
33
{{ renderNode(node) }}
44
</div>
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@
1111
* @link https://phpdoc.org
1212
*/
1313

14-
namespace phpDocumentor\Guides\RestructuredText\Nodes;
15-
16-
use phpDocumentor\Guides\Nodes\CompoundNode;
17-
use phpDocumentor\Guides\Nodes\InlineCompoundNode;
18-
use phpDocumentor\Guides\Nodes\Node;
14+
namespace phpDocumentor\Guides\Nodes;
1915

2016
/** @extends CompoundNode<Node> */
2117
final class AdmonitionNode extends CompoundNode

tests/Integration/tests/bootstrap/bootstrap-admonition/expected/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<!-- content start -->
22
<div class="section" id="document-title">
33
<h1>Document Title</h1>
4-
5-
<div class="alert alert-info " role="alert">
4+
<div class="alert alert-info " role="alert">
65
<h4 class="alert-heading">Tip</h4>
76

87
<p>Lorem Ipsum Dolor.</p>

0 commit comments

Comments
 (0)