From 393db492948a16f246790b88a38a1235cb167659 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Fri, 21 Dec 2018 23:11:44 +0100 Subject: Renderer: Added twig extension for markdown rendering --- src/Renderer/Twig/Extensions/Markdown.php | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/Renderer/Twig/Extensions/Markdown.php (limited to 'src/Renderer/Twig/Extensions') diff --git a/src/Renderer/Twig/Extensions/Markdown.php b/src/Renderer/Twig/Extensions/Markdown.php new file mode 100644 index 00000000..293efe91 --- /dev/null +++ b/src/Renderer/Twig/Extensions/Markdown.php @@ -0,0 +1,43 @@ +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)); + } +} -- cgit v1.2.3-54-g00ecf