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\Inline\Renderer; |
16
|
|
|
|
17
|
|
|
use League\CommonMark\ElementRendererInterface; |
18
|
|
|
use League\CommonMark\Environment; |
19
|
|
|
use League\CommonMark\Inline\Element\AbstractInline; |
20
|
|
|
use League\CommonMark\Inline\Element\HtmlInline; |
21
|
|
|
use League\CommonMark\Util\Configuration; |
22
|
|
|
use League\CommonMark\Util\ConfigurationAwareInterface; |
23
|
|
|
|
24
|
|
|
class HtmlInlineRenderer implements InlineRendererInterface, ConfigurationAwareInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var Configuration |
28
|
|
|
*/ |
29
|
|
|
protected $config; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param HtmlInline $inline |
33
|
|
|
* @param ElementRendererInterface $htmlRenderer |
34
|
|
|
* |
35
|
|
|
* @return string |
36
|
|
|
*/ |
37
|
87 |
|
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer) |
38
|
|
|
{ |
39
|
87 |
|
if (!($inline instanceof HtmlInline)) { |
40
|
3 |
|
throw new \InvalidArgumentException('Incompatible inline type: ' . get_class($inline)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
// Kept for BC reasons |
44
|
84 |
|
if ($this->config->getConfig('safe') === true) { |
45
|
3 |
|
return ''; |
46
|
|
|
} |
47
|
|
|
|
48
|
81 |
|
if ($this->config->getConfig('html_input') === Environment::HTML_INPUT_STRIP) { |
49
|
3 |
|
return ''; |
50
|
|
|
} |
51
|
|
|
|
52
|
78 |
|
if ($this->config->getConfig('html_input') === Environment::HTML_INPUT_ESCAPE) { |
53
|
3 |
|
return htmlspecialchars($inline->getContent(), ENT_NOQUOTES); |
54
|
|
|
} |
55
|
|
|
|
56
|
75 |
|
return $inline->getContent(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param Configuration $configuration |
61
|
|
|
*/ |
62
|
1899 |
|
public function setConfiguration(Configuration $configuration) |
63
|
|
|
{ |
64
|
1899 |
|
$this->config = $configuration; |
65
|
1899 |
|
} |
66
|
|
|
} |
67
|
|
|
|