1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the league/commonmark package. |
5
|
|
|
* |
6
|
|
|
* (c) Colin O'Dell <[email protected]> |
7
|
|
|
* |
8
|
|
|
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) |
9
|
|
|
* - (c) John MacFarlane |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace League\CommonMark\Extension\CommonMark\Renderer\Block; |
16
|
|
|
|
17
|
|
|
use League\CommonMark\Configuration\ConfigurationAwareInterface; |
18
|
|
|
use League\CommonMark\Configuration\ConfigurationInterface; |
19
|
|
|
use League\CommonMark\Environment\EnvironmentInterface; |
20
|
|
|
use League\CommonMark\Extension\CommonMark\Node\Block\HtmlBlock; |
21
|
|
|
use League\CommonMark\Node\Block\AbstractBlock; |
22
|
|
|
use League\CommonMark\Renderer\Block\BlockRendererInterface; |
23
|
|
|
use League\CommonMark\Renderer\NodeRendererInterface; |
24
|
|
|
use League\CommonMark\Util\HtmlFilter; |
25
|
|
|
|
26
|
|
|
final class HtmlBlockRenderer implements BlockRendererInterface, ConfigurationAwareInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var ConfigurationInterface |
30
|
|
|
*/ |
31
|
|
|
protected $config; |
32
|
|
|
|
33
|
|
|
/* |
34
|
|
|
* @param HtmlBlock $block |
35
|
|
|
* @param NodeRendererInterface $htmlRenderer |
36
|
|
|
* @param bool $inTightList |
37
|
|
|
* |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
183 |
|
public function render(AbstractBlock $block, NodeRendererInterface $htmlRenderer, bool $inTightList = false) |
41
|
|
|
{ |
42
|
183 |
|
if (!($block instanceof HtmlBlock)) { |
43
|
3 |
|
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block)); |
44
|
|
|
} |
45
|
|
|
|
46
|
180 |
|
return HtmlFilter::filter($block->getStringContent(), $this->config->get('html_input', HtmlFilter::ALLOW)); |
47
|
|
|
} |
48
|
|
|
|
49
|
2505 |
|
public function setConfiguration(ConfigurationInterface $configuration): void |
50
|
|
|
{ |
51
|
2505 |
|
$this->config = $configuration; |
52
|
2505 |
|
} |
53
|
|
|
} |
54
|
|
|
|