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 TableRowRenderer implements BlockRendererInterface
24{
25    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
26    {
27        if (!$block instanceof TableRow) {
28            throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
29        }
30
31        $attrs = $block->getData('attributes', []);
32
33        $separator = $htmlRenderer->getOption('inner_separator', "\n");
34
35        return new HtmlElement('tr', $attrs, $separator . $htmlRenderer->renderBlocks($block->children()) . $separator);
36    }
37}
38