blob: 293efe91b864b6d612de42c59eb784534847253d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
<?php
namespace Engelsystem\Renderer\Twig\Extensions;
use Parsedown;
use Twig_Extension as TwigExtension;
use Twig_Filter as TwigFilter;
class Markdown extends TwigExtension
{
/** @var Parsedown */
protected $renderer;
/**
* @param Parsedown $renderer
*/
public function __construct(Parsedown $renderer)
{
$this->renderer = $renderer;
}
/**
* @return array
*/
public function getFilters(): array
{
$options = ['is_safe' => ['html']];
return [
new TwigFilter('markdown', [$this, 'render'], $options),
new TwigFilter('md', [$this, 'render'], $options),
];
}
/**
* @param string $text
* @return string
*/
public function render($text): string
{
return $this->renderer->text(htmlspecialchars($text));
}
}
|