Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Markdown
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFilters
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 render
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Renderer\Twig\Extensions;
6
7use Parsedown;
8use Twig\Extension\AbstractExtension as TwigExtension;
9use Twig\TwigFilter;
10
11class Markdown extends TwigExtension
12{
13    public function __construct(protected Parsedown $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->setSafeMode($escapeHtml)->text($text);
30    }
31}