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

DisallowedRawHtmlExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 15
c 1
b 0
f 0
dl 0
loc 25
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureSchema() 0 4 1
A register() 0 4 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