|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the league/commonmark package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Colin O'Dell <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace League\CommonMark\Extension\InlinesOnly; |
|
13
|
|
|
|
|
14
|
|
|
use League\CommonMark\Configuration\ConfigurationAwareInterface; |
|
15
|
|
|
use League\CommonMark\Configuration\ConfigurationInterface; |
|
16
|
|
|
use League\CommonMark\Node\Block\AbstractBlock; |
|
17
|
|
|
use League\CommonMark\Node\Block\Document; |
|
18
|
|
|
use League\CommonMark\Node\Inline\AbstractInline; |
|
19
|
|
|
use League\CommonMark\Renderer\Block\BlockRendererInterface; |
|
20
|
|
|
use League\CommonMark\Renderer\NodeRendererInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Simply renders child elements as-is, adding newlines as needed. |
|
24
|
|
|
*/ |
|
25
|
|
|
final class ChildRenderer implements BlockRendererInterface, ConfigurationAwareInterface |
|
26
|
|
|
{ |
|
27
|
|
|
/** @var ConfigurationInterface */ |
|
28
|
|
|
private $config; |
|
29
|
|
|
|
|
30
|
3 |
|
public function render(AbstractBlock $block, NodeRendererInterface $htmlRenderer, bool $inTightList = false) |
|
31
|
|
|
{ |
|
32
|
3 |
|
$out = ''; |
|
33
|
3 |
|
$lastItemWasBlock = false; |
|
34
|
|
|
|
|
35
|
3 |
|
foreach ($block->children() as $child) { |
|
36
|
3 |
|
if ($lastItemWasBlock) { |
|
37
|
3 |
|
$lastItemWasBlock = false; |
|
38
|
3 |
|
$out .= $this->config->get('renderer/block_separator', "\n"); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
3 |
|
if ($child instanceof AbstractBlock) { |
|
42
|
3 |
|
$out .= $htmlRenderer->renderBlock($child, $inTightList); |
|
43
|
3 |
|
$lastItemWasBlock = true; |
|
44
|
3 |
|
} elseif ($child instanceof AbstractInline) { |
|
45
|
3 |
|
$out .= $htmlRenderer->renderInline($child); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
3 |
|
if (!$block instanceof Document) { |
|
50
|
3 |
|
$out .= $this->config->get('renderer/block_separator', "\n"); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
3 |
|
return $out; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
3 |
|
public function setConfiguration(ConfigurationInterface $configuration): void |
|
57
|
|
|
{ |
|
58
|
3 |
|
$this->config = $configuration; |
|
59
|
3 |
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|