Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
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\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
    public function configureSchema(ConfigurationBuilderInterface $builder): void
25
    {
26
        $applyOptions = [
27
            ExternalLinkProcessor::APPLY_NONE,
28
            ExternalLinkProcessor::APPLY_ALL,
29
            ExternalLinkProcessor::APPLY_INTERNAL,
30
            ExternalLinkProcessor::APPLY_EXTERNAL,
31
        ];
32
 
33
        $builder->addSchema('external_link', Expect::structure([
34
            'internal_hosts' => Expect::type('string|string[]'),
35
            'open_in_new_window' => Expect::bool(false),
36
            'html_class' => Expect::string()->default(''),
37
            'nofollow' => Expect::anyOf(...$applyOptions)->default(ExternalLinkProcessor::APPLY_NONE),
38
            'noopener' => Expect::anyOf(...$applyOptions)->default(ExternalLinkProcessor::APPLY_EXTERNAL),
39
            'noreferrer' => Expect::anyOf(...$applyOptions)->default(ExternalLinkProcessor::APPLY_EXTERNAL),
40
        ]));
41
    }
42
 
43
    public function register(EnvironmentBuilderInterface $environment): void
44
    {
45
        $environment->addEventListener(DocumentParsedEvent::class, new ExternalLinkProcessor($environment->getConfiguration()), -50);
46
    }
47
}