-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1131 from phpDocumentor/feature/md-admonitions
[FEATURE] Support GitHub like Markdown Admonitions
- Loading branch information
Showing
18 changed files
with
256 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
packages/guides-theme-bootstrap/resources/template/body/admonition.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/guides-theme-bootstrap/resources/template/body/admonitions/caution.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="alert alert-danger {{ class ? (' '~class) }}{% if node.classes %} {{ node.classesString }}{% endif %}" role="alert"> | ||
<h4 class="alert-heading">Caution</h4> | ||
{{ renderNode(node) }} | ||
</div> |
4 changes: 2 additions & 2 deletions
4
packages/guides-theme-bootstrap/resources/template/body/admonitions/important.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<div class="alert alert-danger {{ class ? (' '~class) }}{% if node.classes %} {{ node.classesString }}{% endif %}" role="alert"> | ||
<h4 class="alert-heading">Tip</h4> | ||
<div class="alert alert-warning {{ class ? (' '~class) }}{% if node.classes %} {{ node.classesString }}{% endif %}" role="alert"> | ||
<h4 class="alert-heading">Imortant</h4> | ||
{{ renderNode(node) }} | ||
</div> |
2 changes: 1 addition & 1 deletion
2
packages/guides-theme-bootstrap/resources/template/body/admonitions/warning.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<div class="alert alert-danger {{ class ? (' '~class) }}{% if node.classes %} {{ node.classesString }}{% endif %}" role="alert"> | ||
<h4 class="alert-heading">Tip</h4> | ||
<h4 class="alert-heading">Warning</h4> | ||
{{ renderNode(node) }} | ||
</div> |
59 changes: 59 additions & 0 deletions
59
packages/guides/src/NodeRenderers/Html/AdmonitionNodeRenderer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of phpDocumentor. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @link https://phpdoc.org | ||
*/ | ||
|
||
namespace phpDocumentor\Guides\NodeRenderers\Html; | ||
|
||
use InvalidArgumentException; | ||
use phpDocumentor\Guides\NodeRenderers\NodeRenderer; | ||
use phpDocumentor\Guides\Nodes\AdmonitionNode; | ||
use phpDocumentor\Guides\Nodes\Node; | ||
use phpDocumentor\Guides\RenderContext; | ||
use phpDocumentor\Guides\TemplateRenderer; | ||
|
||
use function implode; | ||
use function is_a; | ||
|
||
/** @implements NodeRenderer<AdmonitionNode> */ | ||
class AdmonitionNodeRenderer implements NodeRenderer | ||
{ | ||
public function __construct(private readonly TemplateRenderer $renderer) | ||
{ | ||
} | ||
|
||
public function supports(string $nodeFqcn): bool | ||
{ | ||
return $nodeFqcn === AdmonitionNode::class || is_a($nodeFqcn, AdmonitionNode::class, true); | ||
} | ||
|
||
public function render(Node $node, RenderContext $renderContext): string | ||
{ | ||
if ($node instanceof AdmonitionNode === false) { | ||
throw new InvalidArgumentException('Node must be an instance of ' . AdmonitionNode::class); | ||
} | ||
|
||
$classes = $node->getClasses(); | ||
|
||
return $this->renderer->renderTemplate( | ||
$renderContext, | ||
'body/admonition.html.twig', | ||
[ | ||
'name' => $node->getName(), | ||
'text' => $node->getText(), | ||
'title' => $node->getTitle(), | ||
'isTitled' => $node->isTitled(), | ||
'class' => implode(' ', $classes), | ||
'node' => $node->getValue(), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of phpDocumentor. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @link https://phpdoc.org | ||
*/ | ||
|
||
namespace phpDocumentor\Guides\Nodes; | ||
|
||
/** @extends CompoundNode<Node> */ | ||
class AdmonitionNode extends CompoundNode | ||
{ | ||
/** @param Node[] $value */ | ||
public function __construct(private readonly string $name, private readonly InlineCompoundNode|null $title, private readonly string $text, array $value, private readonly bool $isTitled = false) | ||
{ | ||
parent::__construct($value); | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getTitle(): InlineCompoundNode|null | ||
{ | ||
return $this->title; | ||
} | ||
|
||
public function getText(): string | ||
{ | ||
return $this->text; | ||
} | ||
|
||
public function isTitled(): bool | ||
{ | ||
return $this->isTitled; | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
tests/Integration/tests/bootstrap/bootstrap-admonition/expected/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 9 additions & 5 deletions
14
tests/Integration/tests/directives/directive-raw-custom-sanitizer/expected/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
<!-- content start --> | ||
<div class="section" id="directive-tests"> | ||
<h1>Directive tests</h1> | ||
<p>Lorem Ipsum Dolor</p> | ||
<p>Dolor sit!</p> | ||
</div> | ||
<div class="section" id="directive-tests"> | ||
<h1>Directive tests</h1> | ||
|
||
|
||
<p>Lorem Ipsum Dolor</p> | ||
|
||
<p>Dolor sit!</p> | ||
|
||
</div> | ||
<!-- content end --> |
15 changes: 8 additions & 7 deletions
15
tests/Integration/tests/directives/directive-raw-default-sanitizer/expected/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
<!-- content start --> | ||
<div class="section" id="directive-tests"> | ||
<h1>Directive tests</h1> | ||
<div> | ||
<p>Lorem Ipsum Dolor</p> | ||
<h2>Some Rubric</h2> | ||
<p>Dolor sit!</p> | ||
</div> | ||
<div class="section" id="directive-tests"> | ||
<h1>Directive tests</h1> | ||
<div> | ||
|
||
<p>Lorem Ipsum Dolor</p> | ||
<h2>Some Rubric</h2> | ||
<p>Dolor sit!</p> | ||
</div> | ||
</div> | ||
<!-- content end --> |
Oops, something went wrong.