-
-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathCommonMarkEnvironmentFactory.php
More file actions
42 lines (36 loc) · 1.29 KB
/
CommonMarkEnvironmentFactory.php
File metadata and controls
42 lines (36 loc) · 1.29 KB
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
<?php
namespace Fig\Website;
use League\CommonMark\Block\Element\FencedCode;
use League\CommonMark\Block\Element\IndentedCode;
use League\CommonMark\Environment;
use League\CommonMark\EnvironmentInterface;
use League\CommonMark\Extension\HeadingPermalink\HeadingPermalinkExtension;
use League\CommonMark\Extension\Table\TableExtension;
use Spatie\CommonMarkHighlighter\FencedCodeRenderer;
use Spatie\CommonMarkHighlighter\IndentedCodeRenderer;
class CommonMarkEnvironmentFactory
{
public static function create(): EnvironmentInterface
{
$supportedLanguages = [
'php',
'http', # inside PSR-7
];
$config = [
'heading_permalink' => [
'id_prefix' => '',
'fragment_prefix' => '',
'insert' => 'after',
],
];
$environment = Environment::createCommonMarkEnvironment();
$environment->mergeConfig($config);
$environment
->addExtension(new TableExtension())
->addExtension(new HeadingPermalinkExtension())
->addBlockRenderer(FencedCode::class, new FencedCodeRenderer($supportedLanguages))
->addBlockRenderer(IndentedCode::class, new IndentedCodeRenderer($supportedLanguages))
;
return $environment;
}
}