lib: Introduce Markdown view helper

refs #3684
This commit is contained in:
Johannes Meyer 2019-06-04 15:21:20 +02:00
parent 245f392a9d
commit 1ac5557187
2 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,15 @@
<?php
/* Icinga Web 2 | (c) 2019 Icinga GmbH | GPLv2+ */
namespace Icinga\Web\Helper;
use Parsedown;
class Markdown
{
public static function text($content)
{
require_once 'Parsedown/Parsedown.php';
return HtmlPurifier::process(Parsedown::instance()->text($content));
}
}

View File

@ -4,6 +4,7 @@
namespace Icinga\Web\View;
use Icinga\Util\StringHelper;
use Icinga\Web\Helper\Markdown;
$this->addHelperFunction('ellipsis', function ($string, $maxLength, $ellipsis = '...') {
return StringHelper::ellipsis($string, $maxLength, $ellipsis);
@ -12,3 +13,7 @@ $this->addHelperFunction('ellipsis', function ($string, $maxLength, $ellipsis =
$this->addHelperFunction('nl2br', function ($string) {
return nl2br(str_replace(array('\r\n', '\r', '\n'), '<br>', $string), false);
});
$this->addHelperFunction('markdown', function ($content) {
return Markdown::text($content);
});