1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the league/commonmark package. |
5
|
|
|
* |
6
|
|
|
* (c) Colin O'Dell <[email protected]> |
7
|
|
|
* (c) 2015 Martin Hasoň <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
declare(strict_types=1); |
14
|
|
|
|
15
|
|
|
namespace League\CommonMark\Extension\Attributes; |
16
|
|
|
|
17
|
|
|
use League\CommonMark\Environment\EnvironmentBuilderInterface; |
18
|
|
|
use League\CommonMark\Event\DocumentParsedEvent; |
19
|
|
|
use League\CommonMark\Extension\Attributes\Event\AttributesListener; |
20
|
|
|
use League\CommonMark\Extension\Attributes\Parser\AttributesBlockStartParser; |
21
|
|
|
use League\CommonMark\Extension\Attributes\Parser\AttributesInlineParser; |
22
|
|
|
use League\CommonMark\Extension\ConfigurableExtensionInterface; |
23
|
|
|
use League\Config\ConfigurationBuilderInterface; |
24
|
|
|
use Nette\Schema\Expect; |
25
|
|
|
|
26
|
|
|
final class AttributesExtension implements ConfigurableExtensionInterface |
27
|
|
|
{ |
28
|
22 |
|
public function configureSchema(ConfigurationBuilderInterface $builder): void |
29
|
|
|
{ |
30
|
22 |
|
$builder->addSchema('attributes', Expect::structure([ |
31
|
22 |
|
'allow' => Expect::arrayOf('string')->default([]), |
32
|
22 |
|
])); |
33
|
|
|
} |
34
|
|
|
|
35
|
22 |
|
public function register(EnvironmentBuilderInterface $environment): void |
36
|
|
|
{ |
37
|
22 |
|
$allowList = $environment->getConfiguration()->get('attributes.allow'); |
38
|
22 |
|
$allowUnsafeLinks = $environment->getConfiguration()->get('allow_unsafe_links'); |
39
|
|
|
|
40
|
22 |
|
$environment->addBlockStartParser(new AttributesBlockStartParser()); |
41
|
22 |
|
$environment->addInlineParser(new AttributesInlineParser()); |
42
|
22 |
|
$environment->addEventListener(DocumentParsedEvent::class, [new AttributesListener($allowList, $allowUnsafeLinks), 'processDocument']); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|