summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-03-04 01:46:45 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-03-04 01:46:45 +0300
commiteeb84c5be16ecca239adae9c851bc0f7db0875a1 (patch)
tree9aa1056e643212e4c6133d90f38a1966f0fa35ca /lib
parent917d2622aa5fe748c1cda914eae94c12be743c42 (diff)
blog: support ToC
Diffstat (limited to 'lib')
-rw-r--r--lib/MyParsedown.php9
-rw-r--r--lib/markup.php13
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);