diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MyParsedown.php | 9 | ||||
-rw-r--r-- | lib/markup.php | 13 |
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/MyParsedown.php b/lib/MyParsedown.php index cd537bc..85ed9c4 100644 --- a/lib/MyParsedown.php +++ b/lib/MyParsedown.php @@ -3,13 +3,18 @@ class MyParsedown extends ParsedownExtended { public function __construct( + ?array $opts = null, protected bool $useImagePreviews = false ) { - parent::__construct([ + $parsedown_opts = [ 'tables' => [ 'tablespan' => true ] - ]); + ]; + if (!is_null($opts)) { + $parsedown_opts = array_merge($parsedown_opts, $opts); + } + parent::__construct($parsedown_opts); $this->InlineTypes['{'][] = 'FileAttach'; $this->InlineTypes['{'][] = 'Image'; diff --git a/lib/markup.php b/lib/markup.php index 2f25c6c..f6ddd0f 100644 --- a/lib/markup.php +++ b/lib/markup.php @@ -7,6 +7,19 @@ class markup { return $pd->text($md); } + public static function toc(string $md): string { + $pd = new MyParsedown([ + 'toc' => [ + 'lowercase' => true, + 'transliterate' => true, + 'urlencode' => false, + 'headings' => ['h1', 'h2', 'h3'] + ] + ]); + $pd->text($md); + return $pd->contentsList(); + } + public static function htmlToText(string $html): string { $text = html_entity_decode(strip_tags($html)); $lines = explode("\n", $text); |