summaryrefslogtreecommitdiffstats
path: root/library/Icinga/Web/Helper/Markdown.php
blob: e6509d0541311a6288e7e7734fa683112cc34dcd (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
<?php
/* Icinga Web 2 | (c) 2019 Icinga GmbH | GPLv2+ */

namespace Icinga\Web\Helper;

use Icinga\Web\Helper\Markdown\LinkTransformer;
use Parsedown;

class Markdown
{
    public static function line($content, $config = null)
    {
        require_once 'Parsedown/Parsedown.php';

        if ($config === null) {
            $config = function (\HTMLPurifier_Config $config) {
                $config->set('HTML.Parent', 'span'); // Only allow inline elements

                LinkTransformer::attachTo($config);
            };
        }

        return HtmlPurifier::process(Parsedown::instance()->line($content), $config);
    }

    public static function text($content, $config = null)
    {
        require_once 'Parsedown/Parsedown.php';

        if ($config === null) {
            $config = function (\HTMLPurifier_Config $config) {
                LinkTransformer::attachTo($config);
            };
        }

        return HtmlPurifier::process(Parsedown::instance()->text($content), $config);
    }
}