2019-06-04 15:21:20 +02:00
|
|
|
<?php
|
|
|
|
/* Icinga Web 2 | (c) 2019 Icinga GmbH | GPLv2+ */
|
|
|
|
|
|
|
|
namespace Icinga\Web\Helper;
|
|
|
|
|
2021-04-27 13:10:49 +02:00
|
|
|
use Icinga\Web\Helper\Markdown\LinkTransformer;
|
2019-06-04 15:21:20 +02:00
|
|
|
use Parsedown;
|
|
|
|
|
|
|
|
class Markdown
|
|
|
|
{
|
2021-04-27 13:10:49 +02:00
|
|
|
public static function line($content, $config = null)
|
2019-10-31 14:41:13 +01:00
|
|
|
{
|
2021-04-27 13:10:49 +02:00
|
|
|
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);
|
2019-10-31 14:41:13 +01:00
|
|
|
}
|
|
|
|
|
2021-04-27 13:10:49 +02:00
|
|
|
public static function text($content, $config = null)
|
2019-06-04 15:21:20 +02:00
|
|
|
{
|
2021-04-27 13:10:49 +02:00
|
|
|
if ($config === null) {
|
|
|
|
$config = function (\HTMLPurifier_Config $config) {
|
|
|
|
LinkTransformer::attachTo($config);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return HtmlPurifier::process(Parsedown::instance()->text($content), $config);
|
2019-06-04 15:21:20 +02:00
|
|
|
}
|
|
|
|
}
|