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
|
|
|
|
25
|
|
|
final class HtmlBlockRenderer implements BlockRendererInterface, ConfigurationAwareInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var ConfigurationInterface |
29
|
|
|
*/ |
30
|
|
|
protected $config; |
31
|
|
|
|
32
|
|
|
* @param HtmlBlock $block |
|
|
|
|
33
|
|
|
* @param NodeRendererInterface $htmlRenderer |
34
|
|
|
* @param bool $inTightList |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
public function render(AbstractBlock $block, NodeRendererInterface $htmlRenderer, bool $inTightList = false) |
39
|
|
|
{ |
40
|
|
|
if (!($block instanceof HtmlBlock)) { |
41
|
|
|
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_STRIP) { |
45
|
|
|
return ''; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_ESCAPE) { |
49
|
|
|
return \htmlspecialchars($block->getStringContent(), \ENT_NOQUOTES); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $block->getStringContent(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function setConfiguration(ConfigurationInterface $configuration): void |
56
|
|
|
{ |
57
|
|
|
$this->config = $configuration; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|