1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the league/commonmark package. |
5
|
|
|
* |
6
|
|
|
* (c) Colin O'Dell <[email protected]> |
7
|
|
|
* |
8
|
|
|
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) |
9
|
|
|
* - (c) John MacFarlane |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace League\CommonMark\Extension; |
16
|
|
|
|
17
|
|
|
use League\CommonMark\Block\Element as BlockElement; |
18
|
|
|
use League\CommonMark\Block\Parser as BlockParser; |
19
|
|
|
use League\CommonMark\Block\Renderer as BlockRenderer; |
20
|
|
|
use League\CommonMark\ConfigurableEnvironmentInterface; |
21
|
|
|
use League\CommonMark\Delimiter\Processor\EmphasisDelimiterProcessor; |
22
|
|
|
use League\CommonMark\Inline\Element as InlineElement; |
23
|
|
|
use League\CommonMark\Inline\Parser as InlineParser; |
24
|
|
|
use League\CommonMark\Inline\Renderer as InlineRenderer; |
25
|
|
|
use League\CommonMark\Util\ConfigurationInterface; |
26
|
|
|
|
27
|
|
|
final class CommonMarkCoreExtension implements ExtensionInterface |
28
|
|
|
{ |
29
|
2904 |
|
public function register(ConfigurableEnvironmentInterface $environment) |
30
|
|
|
{ |
31
|
|
|
$environment |
32
|
2904 |
|
->addBlockParser(new BlockParser\BlockQuoteParser(), 70) |
33
|
2904 |
|
->addBlockParser(new BlockParser\ATXHeadingParser(), 60) |
34
|
2904 |
|
->addBlockParser(new BlockParser\FencedCodeParser(), 50) |
35
|
2904 |
|
->addBlockParser(new BlockParser\HtmlBlockParser(), 40) |
36
|
2904 |
|
->addBlockParser(new BlockParser\SetExtHeadingParser(), 30) |
37
|
2904 |
|
->addBlockParser(new BlockParser\ThematicBreakParser(), 20) |
38
|
2904 |
|
->addBlockParser(new BlockParser\ListParser(), 10) |
39
|
2904 |
|
->addBlockParser(new BlockParser\IndentedCodeParser(), -100) |
40
|
2904 |
|
->addBlockParser(new BlockParser\LazyParagraphParser(), -200) |
41
|
|
|
|
42
|
2904 |
|
->addInlineParser(new InlineParser\NewlineParser(), 200) |
43
|
2904 |
|
->addInlineParser(new InlineParser\BacktickParser(), 150) |
44
|
2904 |
|
->addInlineParser(new InlineParser\EscapableParser(), 80) |
45
|
2904 |
|
->addInlineParser(new InlineParser\EntityParser(), 70) |
46
|
2904 |
|
->addInlineParser(new InlineParser\AutolinkParser(), 50) |
47
|
2904 |
|
->addInlineParser(new InlineParser\HtmlInlineParser(), 40) |
48
|
2904 |
|
->addInlineParser(new InlineParser\CloseBracketParser(), 30) |
49
|
2904 |
|
->addInlineParser(new InlineParser\OpenBracketParser(), 20) |
50
|
2904 |
|
->addInlineParser(new InlineParser\BangParser(), 10) |
51
|
|
|
|
52
|
2904 |
|
->addBlockRenderer(BlockElement\BlockQuote::class, new BlockRenderer\BlockQuoteRenderer(), 0) |
53
|
2904 |
|
->addBlockRenderer(BlockElement\Document::class, new BlockRenderer\DocumentRenderer(), 0) |
54
|
2904 |
|
->addBlockRenderer(BlockElement\FencedCode::class, new BlockRenderer\FencedCodeRenderer(), 0) |
55
|
2904 |
|
->addBlockRenderer(BlockElement\Heading::class, new BlockRenderer\HeadingRenderer(), 0) |
56
|
2904 |
|
->addBlockRenderer(BlockElement\HtmlBlock::class, new BlockRenderer\HtmlBlockRenderer(), 0) |
57
|
2904 |
|
->addBlockRenderer(BlockElement\IndentedCode::class, new BlockRenderer\IndentedCodeRenderer(), 0) |
58
|
2904 |
|
->addBlockRenderer(BlockElement\ListBlock::class, new BlockRenderer\ListBlockRenderer(), 0) |
59
|
2904 |
|
->addBlockRenderer(BlockElement\ListItem::class, new BlockRenderer\ListItemRenderer(), 0) |
60
|
2904 |
|
->addBlockRenderer(BlockElement\Paragraph::class, new BlockRenderer\ParagraphRenderer(), 0) |
61
|
2904 |
|
->addBlockRenderer(BlockElement\ThematicBreak::class, new BlockRenderer\ThematicBreakRenderer(), 0) |
62
|
|
|
|
63
|
2904 |
|
->addInlineRenderer(InlineElement\Code::class, new InlineRenderer\CodeRenderer(), 0) |
64
|
2904 |
|
->addInlineRenderer(InlineElement\Emphasis::class, new InlineRenderer\EmphasisRenderer(), 0) |
65
|
2904 |
|
->addInlineRenderer(InlineElement\HtmlInline::class, new InlineRenderer\HtmlInlineRenderer(), 0) |
66
|
2904 |
|
->addInlineRenderer(InlineElement\Image::class, new InlineRenderer\ImageRenderer(), 0) |
67
|
2904 |
|
->addInlineRenderer(InlineElement\Link::class, new InlineRenderer\LinkRenderer(), 0) |
68
|
2904 |
|
->addInlineRenderer(InlineElement\Newline::class, new InlineRenderer\NewlineRenderer(), 0) |
69
|
2904 |
|
->addInlineRenderer(InlineElement\Strong::class, new InlineRenderer\StrongRenderer(), 0) |
70
|
2904 |
|
->addInlineRenderer(InlineElement\Text::class, new InlineRenderer\TextRenderer(), 0) |
71
|
|
|
; |
72
|
|
|
|
73
|
2904 |
|
$deprecatedUseAsterisk = $environment->getConfig('use_asterisk', ConfigurationInterface::MISSING); |
|
|
|
|
74
|
2904 |
|
if ($deprecatedUseAsterisk !== ConfigurationInterface::MISSING) { |
|
|
|
|
75
|
12 |
|
@\trigger_error('The "use_asterisk" configuration option is deprecated in league/commonmark 1.6 and will be replaced with "commonmark > use_asterisk" in 2.0', \E_USER_DEPRECATED); |
76
|
|
|
} else { |
77
|
2892 |
|
$deprecatedUseAsterisk = true; |
78
|
|
|
} |
79
|
|
|
|
80
|
2904 |
|
if ($environment->getConfig('commonmark/use_asterisk', $deprecatedUseAsterisk)) { |
81
|
2895 |
|
$environment->addDelimiterProcessor(new EmphasisDelimiterProcessor('*')); |
82
|
|
|
} |
83
|
|
|
|
84
|
2904 |
|
$deprecatedUseUnderscore = $environment->getConfig('use_underscore', ConfigurationInterface::MISSING); |
|
|
|
|
85
|
2904 |
|
if ($deprecatedUseUnderscore !== ConfigurationInterface::MISSING) { |
|
|
|
|
86
|
12 |
|
@\trigger_error('The "use_underscore" configuration option is deprecated in league/commonmark 1.6 and will be replaced with "commonmark > use_underscore" in 2.0', \E_USER_DEPRECATED); |
87
|
|
|
} else { |
88
|
2892 |
|
$deprecatedUseUnderscore = true; |
89
|
|
|
} |
90
|
|
|
|
91
|
2904 |
|
if ($environment->getConfig('commonmark/use_underscore', $deprecatedUseUnderscore)) { |
92
|
2895 |
|
$environment->addDelimiterProcessor(new EmphasisDelimiterProcessor('_')); |
93
|
|
|
} |
94
|
2904 |
|
} |
95
|
|
|
} |
96
|
|
|
|
This class constant has been deprecated.