Passed
Pull Request — latest (#598)
by Colin
16:46 queued 13:48
created

DisallowedRawHtmlExtension::configureSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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\DisallowedRawHtml;
15
16
use League\CommonMark\Configuration\ConfigurationBuilderInterface;
17
use League\CommonMark\Environment\EnvironmentBuilderInterface;
18
use League\CommonMark\Extension\CommonMark\Node\Block\HtmlBlock;
19
use League\CommonMark\Extension\CommonMark\Node\Inline\HtmlInline;
20
use League\CommonMark\Extension\CommonMark\Renderer\Block\HtmlBlockRenderer;
21
use League\CommonMark\Extension\CommonMark\Renderer\Inline\HtmlInlineRenderer;
22
use League\CommonMark\Extension\ConfigurableExtensionInterface;
23
use Nette\Schema\Expect;
24
25
final class DisallowedRawHtmlExtension implements ConfigurableExtensionInterface
26
{
27
    private const DEFAULT_DISALLOWED_TAGS = [
28
        'title',
29
        'textarea',
30
        'style',
31
        'xmp',
32
        'iframe',
33
        'noembed',
34
        'noframes',
35
        'script',
36
        'plaintext',
37
    ];
38
39 213
    public function configureSchema(ConfigurationBuilderInterface $builder): void
40
    {
41 213
        $builder->addSchema('disallowed_raw_html', Expect::structure([
42 213
            'disallowed_tags' => Expect::listOf('string')->default(self::DEFAULT_DISALLOWED_TAGS)->mergeDefaults(false),
43
        ]));
44 213
    }
45
46 126
    public function register(EnvironmentBuilderInterface $environment): void
47
    {
48 126
        $environment->addRenderer(HtmlBlock::class, new DisallowedRawHtmlRenderer(new HtmlBlockRenderer()), 50);
49 126
        $environment->addRenderer(HtmlInline::class, new DisallowedRawHtmlRenderer(new HtmlInlineRenderer()), 50);
50 126
    }
51
}
52