|
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
|
|
|
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) |
|
11
|
|
|
* - (c) John MacFarlane |
|
12
|
|
|
* |
|
13
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
14
|
|
|
* file that was distributed with this source code. |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace League\CommonMark\Extension\CommonMark\Renderer\Block; |
|
18
|
|
|
|
|
19
|
|
|
use League\CommonMark\Configuration\ConfigurationAwareInterface; |
|
20
|
|
|
use League\CommonMark\Configuration\ConfigurationInterface; |
|
21
|
|
|
use League\CommonMark\Exception\InvalidOptionException; |
|
22
|
|
|
use League\CommonMark\Extension\CommonMark\Node\Block\HtmlBlock; |
|
23
|
|
|
use League\CommonMark\Node\Node; |
|
24
|
|
|
use League\CommonMark\Renderer\ChildNodeRendererInterface; |
|
25
|
|
|
use League\CommonMark\Renderer\NodeRendererInterface; |
|
26
|
|
|
use League\CommonMark\Util\HtmlFilter; |
|
27
|
|
|
|
|
28
|
|
|
final class HtmlBlockRenderer implements NodeRendererInterface, ConfigurationAwareInterface |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var ConfigurationInterface |
|
32
|
|
|
* |
|
33
|
|
|
* @psalm-readonly-allow-private-mutation |
|
34
|
|
|
*/ |
|
35
|
|
|
private $config; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param HtmlBlock $node |
|
39
|
|
|
* |
|
40
|
|
|
* {@inheritdoc} |
|
41
|
|
|
* |
|
42
|
|
|
* @psalm-suppress MoreSpecificImplementedParamType |
|
43
|
|
|
*/ |
|
44
|
183 |
|
public function render(Node $node, ChildNodeRendererInterface $childRenderer) |
|
45
|
|
|
{ |
|
46
|
183 |
|
if (! ($node instanceof HtmlBlock)) { |
|
47
|
3 |
|
throw new \InvalidArgumentException('Incompatible node type: ' . \get_class($node)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
180 |
|
$htmlInput = $this->config->get('html_input', HtmlFilter::ALLOW); |
|
51
|
180 |
|
if (! \is_string($htmlInput)) { |
|
52
|
|
|
throw InvalidOptionException::forConfigOption('html_input', $htmlInput); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
180 |
|
return HtmlFilter::filter($node->getLiteral(), $htmlInput); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
2508 |
|
public function setConfiguration(ConfigurationInterface $configuration): void |
|
59
|
|
|
{ |
|
60
|
2508 |
|
$this->config = $configuration; |
|
61
|
2508 |
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|