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