1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the league/commonmark package. |
7
|
|
|
* |
8
|
|
|
* (c) Colin O'Dell <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace League\CommonMark\Extension\InlinesOnly; |
15
|
|
|
|
16
|
|
|
use League\CommonMark as Core; |
17
|
|
|
use League\CommonMark\Environment\EnvironmentBuilderInterface; |
18
|
|
|
use League\CommonMark\Extension\CommonMark; |
19
|
|
|
use League\CommonMark\Extension\CommonMark\Delimiter\Processor\EmphasisDelimiterProcessor; |
20
|
|
|
use League\CommonMark\Extension\ConfigurableExtensionInterface; |
21
|
|
|
use League\Config\ConfigurationBuilderInterface; |
22
|
|
|
use Nette\Schema\Expect; |
23
|
|
|
|
24
|
|
|
final class InlinesOnlyExtension implements ConfigurableExtensionInterface |
25
|
|
|
{ |
26
|
3 |
|
public function configureSchema(ConfigurationBuilderInterface $builder): void |
27
|
|
|
{ |
28
|
3 |
|
$builder->addSchema('commonmark', Expect::structure([ |
29
|
3 |
|
'use_asterisk' => Expect::bool(true), |
30
|
3 |
|
'use_underscore' => Expect::bool(true), |
31
|
3 |
|
'enable_strong' => Expect::bool(true), |
32
|
3 |
|
'enable_em' => Expect::bool(true), |
33
|
|
|
])); |
34
|
3 |
|
} |
35
|
|
|
|
36
|
|
|
// phpcs:disable Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma,Squiz.WhiteSpace.SemicolonSpacing.Incorrect |
37
|
3 |
|
public function register(EnvironmentBuilderInterface $environment): void |
38
|
|
|
{ |
39
|
3 |
|
$childRenderer = new ChildRenderer(); |
40
|
|
|
|
41
|
|
|
$environment |
42
|
3 |
|
->addInlineParser(new Core\Parser\Inline\NewlineParser(), 200) |
43
|
3 |
|
->addInlineParser(new CommonMark\Parser\Inline\BacktickParser(), 150) |
44
|
3 |
|
->addInlineParser(new CommonMark\Parser\Inline\EscapableParser(), 80) |
45
|
3 |
|
->addInlineParser(new CommonMark\Parser\Inline\EntityParser(), 70) |
46
|
3 |
|
->addInlineParser(new CommonMark\Parser\Inline\AutolinkParser(), 50) |
47
|
3 |
|
->addInlineParser(new CommonMark\Parser\Inline\HtmlInlineParser(), 40) |
48
|
3 |
|
->addInlineParser(new CommonMark\Parser\Inline\CloseBracketParser(), 30) |
49
|
3 |
|
->addInlineParser(new CommonMark\Parser\Inline\OpenBracketParser(), 20) |
50
|
3 |
|
->addInlineParser(new CommonMark\Parser\Inline\BangParser(), 10) |
51
|
|
|
|
52
|
3 |
|
->addRenderer(Core\Node\Block\Document::class, $childRenderer, 0) |
53
|
3 |
|
->addRenderer(Core\Node\Block\Paragraph::class, $childRenderer, 0) |
54
|
|
|
|
55
|
3 |
|
->addRenderer(CommonMark\Node\Inline\Code::class, new CommonMark\Renderer\Inline\CodeRenderer(), 0) |
56
|
3 |
|
->addRenderer(CommonMark\Node\Inline\Emphasis::class, new CommonMark\Renderer\Inline\EmphasisRenderer(), 0) |
57
|
3 |
|
->addRenderer(CommonMark\Node\Inline\HtmlInline::class, new CommonMark\Renderer\Inline\HtmlInlineRenderer(), 0) |
58
|
3 |
|
->addRenderer(CommonMark\Node\Inline\Image::class, new CommonMark\Renderer\Inline\ImageRenderer(), 0) |
59
|
3 |
|
->addRenderer(CommonMark\Node\Inline\Link::class, new CommonMark\Renderer\Inline\LinkRenderer(), 0) |
60
|
3 |
|
->addRenderer(Core\Node\Inline\Newline::class, new Core\Renderer\Inline\NewlineRenderer(), 0) |
61
|
3 |
|
->addRenderer(CommonMark\Node\Inline\Strong::class, new CommonMark\Renderer\Inline\StrongRenderer(), 0) |
62
|
3 |
|
->addRenderer(Core\Node\Inline\Text::class, new Core\Renderer\Inline\TextRenderer(), 0) |
63
|
|
|
; |
64
|
|
|
|
65
|
3 |
|
if ($environment->getConfiguration()->get('commonmark/use_asterisk')) { |
66
|
3 |
|
$environment->addDelimiterProcessor(new EmphasisDelimiterProcessor('*')); |
67
|
|
|
} |
68
|
|
|
|
69
|
3 |
|
if ($environment->getConfiguration()->get('commonmark/use_underscore')) { |
70
|
3 |
|
$environment->addDelimiterProcessor(new EmphasisDelimiterProcessor('_')); |
71
|
|
|
} |
72
|
3 |
|
} |
73
|
|
|
} |
74
|
|
|
|