|
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\ExternalLink; |
|
15
|
|
|
|
|
16
|
|
|
use League\CommonMark\Environment\EnvironmentBuilderInterface; |
|
17
|
|
|
use League\CommonMark\Event\DocumentParsedEvent; |
|
18
|
|
|
use League\CommonMark\Extension\ConfigurableExtensionInterface; |
|
19
|
|
|
use League\Config\ConfigurationBuilderInterface; |
|
20
|
|
|
use Nette\Schema\Expect; |
|
21
|
|
|
|
|
22
|
|
|
final class ExternalLinkExtension implements ConfigurableExtensionInterface |
|
23
|
|
|
{ |
|
24
|
201 |
|
public function configureSchema(ConfigurationBuilderInterface $builder): void |
|
25
|
|
|
{ |
|
26
|
|
|
$applyOptions = [ |
|
27
|
201 |
|
ExternalLinkProcessor::APPLY_NONE, |
|
28
|
201 |
|
ExternalLinkProcessor::APPLY_ALL, |
|
29
|
201 |
|
ExternalLinkProcessor::APPLY_INTERNAL, |
|
30
|
201 |
|
ExternalLinkProcessor::APPLY_EXTERNAL, |
|
31
|
|
|
]; |
|
32
|
|
|
|
|
33
|
201 |
|
$builder->addSchema('external_link', Expect::structure([ |
|
34
|
201 |
|
'internal_hosts' => Expect::arrayOf('string'), |
|
35
|
201 |
|
'open_in_new_window' => Expect::bool(false), |
|
36
|
201 |
|
'html_class' => Expect::string()->default(''), |
|
37
|
201 |
|
'nofollow' => Expect::anyOf(...$applyOptions)->default(ExternalLinkProcessor::APPLY_NONE), |
|
38
|
201 |
|
'noopener' => Expect::anyOf(...$applyOptions)->default(ExternalLinkProcessor::APPLY_EXTERNAL), |
|
39
|
201 |
|
'noreferrer' => Expect::anyOf(...$applyOptions)->default(ExternalLinkProcessor::APPLY_EXTERNAL), |
|
40
|
|
|
])); |
|
41
|
201 |
|
} |
|
42
|
|
|
|
|
43
|
201 |
|
public function register(EnvironmentBuilderInterface $environment): void |
|
44
|
|
|
{ |
|
45
|
201 |
|
$environment->addEventListener(DocumentParsedEvent::class, new ExternalLinkProcessor($environment->getConfiguration())); |
|
46
|
201 |
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|