-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·59 lines (54 loc) · 1.82 KB
/
index.php
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php namespace x\parsedown;
function page__content($content) {
$type = $this->type;
if (
'Markdown' !== $type &&
'Parsedown' !== $type &&
'text/markdown' !== $type &&
'text/x-parsedown' !== $type
) {
return $content;
}
$out = new \ParsedownExtraPlugin;
foreach (\State::get('x.parsedown', true) ?? [] as $k => $v) {
$out->{$k} = $v;
}
return "" !== ($out = $out->text($content ?? "")) ? $out : null;
}
function page__description($description) {
return \fire(__NAMESPACE__ . "\\page__title", [$description], $this);
}
function page__title($title) {
$type = $this->type;
if (
'Markdown' !== $type &&
'Parsedown' !== $type &&
'text/markdown' !== $type &&
'text/x-parsedown' !== $type
) {
return $title;
}
$out = new \ParsedownExtraPlugin;
foreach (\State::get('x.parsedown', true) ?? [] as $k => $v) {
if (0 === \strpos($k, 'block')) {
continue;
}
$out->{$k} = $v;
}
return "" !== ($out = $out->line($title ?? "")) ? $out : null;
}
\Hook::set('page.content', __NAMESPACE__ . "\\page__content", 2);
\Hook::set('page.description', __NAMESPACE__ . "\\page__description", 2);
\Hook::set('page.title', __NAMESPACE__ . "\\page__title", 2);
// Make property `$state->x->markdown` exist, so that other extension(s) that depend on the Markdown parser can continue
// to work by checking if property `$state->x->markdown` is set:
//
// if (isset($state->x->markdown)) {
// if (isset($state->x->markdown->vendor) && 'erusev/parsedown' === $state->x->markdown->vendor) {
// // Using `erusev/parsedown`
// } else {
// // Using `taufik-nurrohman/markdown`
// }
// }
//
\State::set('x.markdown.vendor', 'erusev/parsedown');