Completed
Push — master ( d214bd...7d804e )
by Colin
50:05 queued 48:49
created

TableRenderer::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This is part of the league/commonmark package.
7
 *
8
 * (c) Martin Hasoň <[email protected]>
9
 * (c) Webuni s.r.o. <[email protected]>
10
 * (c) Colin O'Dell <[email protected]>
11
 *
12
 * For the full copyright and license information, please view the LICENSE
13
 * file that was distributed with this source code.
14
 */
15
16
namespace League\CommonMark\Extension\Table;
17
18
use League\CommonMark\Block\Element\AbstractBlock;
19
use League\CommonMark\Block\Renderer\BlockRendererInterface;
20
use League\CommonMark\ElementRendererInterface;
21
use League\CommonMark\HtmlElement;
22
23
final class TableRenderer implements BlockRendererInterface
24
{
25 75
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
26
    {
27 75
        if (!$block instanceof Table) {
28 3
            throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
29
        }
30
31 72
        $attrs = $block->getData('attributes', []);
32
33 72
        $separator = $htmlRenderer->getOption('inner_separator', "\n");
34
35 72
        $children = $htmlRenderer->renderBlocks($block->children());
36
37 72
        return new HtmlElement('table', $attrs, $separator . \trim($children) . $separator);
38
    }
39
}
40