Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Markdown | |
100.00% |
8 / 8 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFilters | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| render | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Engelsystem\Renderer\Twig\Extensions; |
| 6 | |
| 7 | use Engelsystem\Helpers\Markdown as MarkdownRenderer; |
| 8 | use Twig\Extension\AbstractExtension as TwigExtension; |
| 9 | use Twig\TwigFilter; |
| 10 | |
| 11 | class Markdown extends TwigExtension |
| 12 | { |
| 13 | public function __construct(protected MarkdownRenderer $renderer) |
| 14 | { |
| 15 | } |
| 16 | |
| 17 | public function getFilters(): array |
| 18 | { |
| 19 | $options = ['is_safe' => ['html']]; |
| 20 | |
| 21 | return [ |
| 22 | new TwigFilter('markdown', [$this, 'render'], $options), |
| 23 | new TwigFilter('md', [$this, 'render'], $options), |
| 24 | ]; |
| 25 | } |
| 26 | |
| 27 | public function render(string $text, bool $escapeHtml = true): string |
| 28 | { |
| 29 | return $this->renderer |
| 30 | ->render($text, !$escapeHtml); |
| 31 | } |
| 32 | } |