|
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\Extension\CommonMark\Node\Block\ListBlock; |
|
18
|
|
|
use League\CommonMark\Node\Block\AbstractBlock; |
|
19
|
|
|
use League\CommonMark\Renderer\Block\BlockRendererInterface; |
|
20
|
|
|
use League\CommonMark\Renderer\ElementRendererInterface; |
|
21
|
|
|
use League\CommonMark\Util\HtmlElement; |
|
22
|
|
|
|
|
23
|
|
|
final class ListBlockRenderer implements BlockRendererInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @param ListBlock $block |
|
27
|
|
|
* @param ElementRendererInterface $htmlRenderer |
|
28
|
|
|
* @param bool $inTightList |
|
29
|
|
|
* |
|
30
|
|
|
* @return HtmlElement |
|
31
|
|
|
*/ |
|
32
|
315 |
|
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false) |
|
33
|
|
|
{ |
|
34
|
315 |
|
if (!($block instanceof ListBlock)) { |
|
35
|
3 |
|
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block)); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
312 |
|
$listData = $block->getListData(); |
|
39
|
|
|
|
|
40
|
312 |
|
$tag = $listData->type === ListBlock::TYPE_BULLET ? 'ul' : 'ol'; |
|
41
|
|
|
|
|
42
|
312 |
|
$attrs = $block->getData('attributes', []); |
|
43
|
|
|
|
|
44
|
312 |
|
if ($listData->start !== null && $listData->start !== 1) { |
|
45
|
33 |
|
$attrs['start'] = (string) $listData->start; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
312 |
|
return new HtmlElement( |
|
49
|
312 |
|
$tag, |
|
50
|
104 |
|
$attrs, |
|
51
|
312 |
|
$htmlRenderer->getOption('inner_separator', "\n") . $htmlRenderer->renderBlocks( |
|
52
|
312 |
|
$block->children(), |
|
53
|
312 |
|
$block->isTight() |
|
54
|
312 |
|
) . $htmlRenderer->getOption('inner_separator', "\n") |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|