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