1<?php 2 3declare(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 14namespace League\CommonMark\Extension\DisallowedRawHtml; 15 16use League\CommonMark\Environment\EnvironmentBuilderInterface; 17use League\CommonMark\Extension\CommonMark\Node\Block\HtmlBlock; 18use League\CommonMark\Extension\CommonMark\Node\Inline\HtmlInline; 19use League\CommonMark\Extension\CommonMark\Renderer\Block\HtmlBlockRenderer; 20use League\CommonMark\Extension\CommonMark\Renderer\Inline\HtmlInlineRenderer; 21use League\CommonMark\Extension\ConfigurableExtensionInterface; 22use League\Config\ConfigurationBuilderInterface; 23use Nette\Schema\Expect; 24 25final 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 public function configureSchema(ConfigurationBuilderInterface $builder): void 40 { 41 $builder->addSchema('disallowed_raw_html', Expect::structure([ 42 'disallowed_tags' => Expect::listOf('string')->default(self::DEFAULT_DISALLOWED_TAGS)->mergeDefaults(false), 43 ])); 44 } 45 46 public function register(EnvironmentBuilderInterface $environment): void 47 { 48 $environment->addRenderer(HtmlBlock::class, new DisallowedRawHtmlRenderer(new HtmlBlockRenderer()), 50); 49 $environment->addRenderer(HtmlInline::class, new DisallowedRawHtmlRenderer(new HtmlInlineRenderer()), 50); 50 } 51} 52