| 148 |
lars |
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 <colinodell@gmail.com>
|
|
|
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 |
public function configureSchema(ConfigurationBuilderInterface $builder): void
|
|
|
27 |
{
|
|
|
28 |
$builder->addSchema('commonmark', Expect::structure([
|
|
|
29 |
'use_asterisk' => Expect::bool(true),
|
|
|
30 |
'use_underscore' => Expect::bool(true),
|
|
|
31 |
'enable_strong' => Expect::bool(true),
|
|
|
32 |
'enable_em' => Expect::bool(true),
|
|
|
33 |
]));
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
// phpcs:disable Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma,Squiz.WhiteSpace.SemicolonSpacing.Incorrect
|
|
|
37 |
public function register(EnvironmentBuilderInterface $environment): void
|
|
|
38 |
{
|
|
|
39 |
$childRenderer = new ChildRenderer();
|
|
|
40 |
|
|
|
41 |
$environment
|
|
|
42 |
->addInlineParser(new Core\Parser\Inline\NewlineParser(), 200)
|
|
|
43 |
->addInlineParser(new CommonMark\Parser\Inline\BacktickParser(), 150)
|
|
|
44 |
->addInlineParser(new CommonMark\Parser\Inline\EscapableParser(), 80)
|
|
|
45 |
->addInlineParser(new CommonMark\Parser\Inline\EntityParser(), 70)
|
|
|
46 |
->addInlineParser(new CommonMark\Parser\Inline\AutolinkParser(), 50)
|
|
|
47 |
->addInlineParser(new CommonMark\Parser\Inline\HtmlInlineParser(), 40)
|
|
|
48 |
->addInlineParser(new CommonMark\Parser\Inline\CloseBracketParser(), 30)
|
|
|
49 |
->addInlineParser(new CommonMark\Parser\Inline\OpenBracketParser(), 20)
|
|
|
50 |
->addInlineParser(new CommonMark\Parser\Inline\BangParser(), 10)
|
|
|
51 |
|
|
|
52 |
->addRenderer(Core\Node\Block\Document::class, $childRenderer, 0)
|
|
|
53 |
->addRenderer(Core\Node\Block\Paragraph::class, $childRenderer, 0)
|
|
|
54 |
|
|
|
55 |
->addRenderer(CommonMark\Node\Inline\Code::class, new CommonMark\Renderer\Inline\CodeRenderer(), 0)
|
|
|
56 |
->addRenderer(CommonMark\Node\Inline\Emphasis::class, new CommonMark\Renderer\Inline\EmphasisRenderer(), 0)
|
|
|
57 |
->addRenderer(CommonMark\Node\Inline\HtmlInline::class, new CommonMark\Renderer\Inline\HtmlInlineRenderer(), 0)
|
|
|
58 |
->addRenderer(CommonMark\Node\Inline\Image::class, new CommonMark\Renderer\Inline\ImageRenderer(), 0)
|
|
|
59 |
->addRenderer(CommonMark\Node\Inline\Link::class, new CommonMark\Renderer\Inline\LinkRenderer(), 0)
|
|
|
60 |
->addRenderer(Core\Node\Inline\Newline::class, new Core\Renderer\Inline\NewlineRenderer(), 0)
|
|
|
61 |
->addRenderer(CommonMark\Node\Inline\Strong::class, new CommonMark\Renderer\Inline\StrongRenderer(), 0)
|
|
|
62 |
->addRenderer(Core\Node\Inline\Text::class, new Core\Renderer\Inline\TextRenderer(), 0)
|
|
|
63 |
;
|
|
|
64 |
|
|
|
65 |
if ($environment->getConfiguration()->get('commonmark/use_asterisk')) {
|
|
|
66 |
$environment->addDelimiterProcessor(new EmphasisDelimiterProcessor('*'));
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
if ($environment->getConfiguration()->get('commonmark/use_underscore')) {
|
|
|
70 |
$environment->addDelimiterProcessor(new EmphasisDelimiterProcessor('_'));
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
}
|