1<?php
2
3declare(strict_types=1);
4
5/*
6 * This is part of the league/commonmark package.
7 *
8 * (c) Martin Hasoň <martin.hason@gmail.com>
9 * (c) Webuni s.r.o. <info@webuni.cz>
10 * (c) Colin O'Dell <colinodell@gmail.com>
11 *
12 * For the full copyright and license information, please view the LICENSE
13 * file that was distributed with this source code.
14 */
15
16namespace League\CommonMark\Extension\Table;
17
18use League\CommonMark\Block\Element\AbstractBlock;
19use League\CommonMark\Block\Renderer\BlockRendererInterface;
20use League\CommonMark\ElementRendererInterface;
21use League\CommonMark\HtmlElement;
22
23final class TableSectionRenderer implements BlockRendererInterface
24{
25    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
26    {
27        if (!$block instanceof TableSection) {
28            throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
29        }
30
31        if (!$block->hasChildren()) {
32            return '';
33        }
34
35        $attrs = $block->getData('attributes', []);
36
37        $separator = $htmlRenderer->getOption('inner_separator', "\n");
38
39        return new HtmlElement($block->type, $attrs, $separator . $htmlRenderer->renderBlocks($block->children()) . $separator);
40    }
41}
42