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\Renderer\Inline; |
18
|
|
|
|
19
|
|
|
use League\CommonMark\Node\Inline\Newline; |
20
|
|
|
use League\CommonMark\Node\Node; |
21
|
|
|
use League\CommonMark\Renderer\ChildNodeRendererInterface; |
22
|
|
|
use League\CommonMark\Renderer\NodeRendererInterface; |
23
|
|
|
use League\CommonMark\Util\HtmlElement; |
24
|
|
|
use League\CommonMark\Xml\XmlNodeRendererInterface; |
25
|
|
|
use League\Config\ConfigurationAwareInterface; |
26
|
|
|
use League\Config\ConfigurationInterface; |
27
|
|
|
|
28
|
|
|
final class NewlineRenderer implements NodeRendererInterface, XmlNodeRendererInterface, ConfigurationAwareInterface |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var ConfigurationInterface |
32
|
|
|
* |
33
|
|
|
* @psalm-readonly-allow-private-mutation |
34
|
|
|
*/ |
35
|
|
|
private $config; |
36
|
|
|
|
37
|
3072 |
|
public function setConfiguration(ConfigurationInterface $configuration): void |
38
|
|
|
{ |
39
|
3072 |
|
$this->config = $configuration; |
40
|
3072 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param Newline $node |
44
|
|
|
* |
45
|
|
|
* {@inheritDoc} |
46
|
|
|
* |
47
|
|
|
* @psalm-suppress MoreSpecificImplementedParamType |
48
|
|
|
*/ |
49
|
330 |
|
public function render(Node $node, ChildNodeRendererInterface $childRenderer) |
50
|
|
|
{ |
51
|
330 |
|
Newline::assertInstanceOf($node); |
52
|
|
|
|
53
|
327 |
|
if ($node->getType() === Newline::HARDBREAK) { |
54
|
33 |
|
return new HtmlElement('br', [], '', true) . "\n"; |
55
|
|
|
} |
56
|
|
|
|
57
|
294 |
|
return $this->config->get('renderer/soft_break'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param Newline $node |
62
|
|
|
* |
63
|
|
|
* {@inheritDoc} |
64
|
|
|
* |
65
|
|
|
* @psalm-suppress MoreSpecificImplementedParamType |
66
|
|
|
*/ |
67
|
12 |
|
public function getXmlTagName(Node $node): string |
68
|
|
|
{ |
69
|
12 |
|
Newline::assertInstanceOf($node); |
70
|
|
|
|
71
|
12 |
|
return $node->getType() === Newline::SOFTBREAK ? 'softbreak' : 'linebreak'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritDoc} |
76
|
|
|
*/ |
77
|
12 |
|
public function getXmlAttributes(Node $node): array |
78
|
|
|
{ |
79
|
12 |
|
return []; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|