-
Notifications
You must be signed in to change notification settings - Fork 0
/
commonmark.php
91 lines (82 loc) · 2.69 KB
/
commonmark.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
use League\CommonMark\Extension\Attributes\AttributesExtension;
use League\CommonMark\Extension\CommonMark\Node\Block\BlockQuote;
use League\CommonMark\Extension\CommonMark\Node\Block\Heading;
use League\CommonMark\Extension\CommonMark\Node\Block\ListBlock;
use League\CommonMark\Extension\DefaultAttributes\DefaultAttributesExtension;
use League\CommonMark\Extension\Footnote\FootnoteExtension;
use League\CommonMark\Extension\HeadingPermalink\HeadingPermalinkExtension;
use League\CommonMark\Node\Block\Paragraph;
use Sven\CommonMark\ImageMediaQueries\ImageMediaQueriesExtension;
use Sven\CommonMark\ImageMediaQueries\Shorthands\ColorScheme;
$imageMediaQueriesExtension = new ImageMediaQueriesExtension();
$imageMediaQueriesExtension->addShorthand(new ColorScheme());
return [
'config' => [
'heading_permalink' => headingPermalinkConfig(),
'default_attributes' => defaultAttributeConfig(),
'image_media_queries' => imageMediaQueriesConfig(),
'footnote' => footnoteConfig(),
],
'extensions' => [
new HeadingPermalinkExtension(),
new AttributesExtension(),
new DefaultAttributesExtension(),
$imageMediaQueriesExtension,
new FootnoteExtension(),
],
];
function headingPermalinkConfig(): array
{
return [
'html_class' => 'md:-ml-6 mr-2',
'id_prefix' => '',
'fragment_prefix' => '',
'symbol' => '#',
];
}
function defaultAttributeConfig(): array
{
return [
Paragraph::class => [
'class' => 'mb-6 leading-relaxed',
],
Heading::class => [
'class' => static function (Heading $heading) {
$size = match ($heading->getLevel()) {
2 => 'text-2xl',
3 => 'text-xl',
default => 'text-lg',
};
return [$size, 'font-bold'];
},
],
BlockQuote::class => [
'class' => 'border-l-4 border-indigo-200, pl-4 dark:border-indigo-500',
],
ListBlock::class => [
'class' => static function (ListBlock $list) {
$type = match ($list->getListData()->type) {
ListBlock::TYPE_ORDERED => 'list-decimal',
ListBlock::TYPE_BULLET => 'list-disc',
default => 'list-disc',
};
return [$type, 'ml-8 mb-4'];
}
]
];
}
function imageMediaQueriesConfig(): array
{
return [
'picture_class' => '',
];
}
function footnoteConfig(): array
{
return [
'backref_class' => 'text-sm font-bold',
'container_class' => 'footnotes',
'container_add_hr' => true,
];
}