| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(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 |
|
|
|
16 |
namespace League\CommonMark\Extension\Table;
|
|
|
17 |
|
|
|
18 |
use League\CommonMark\Node\Node;
|
|
|
19 |
use League\CommonMark\Renderer\ChildNodeRendererInterface;
|
|
|
20 |
use League\CommonMark\Renderer\NodeRendererInterface;
|
|
|
21 |
use League\CommonMark\Util\HtmlElement;
|
|
|
22 |
use League\CommonMark\Xml\XmlNodeRendererInterface;
|
|
|
23 |
|
|
|
24 |
final class TableSectionRenderer implements NodeRendererInterface, XmlNodeRendererInterface
|
|
|
25 |
{
|
|
|
26 |
/**
|
|
|
27 |
* @param TableSection $node
|
|
|
28 |
*
|
|
|
29 |
* {@inheritDoc}
|
|
|
30 |
*
|
|
|
31 |
* @psalm-suppress MoreSpecificImplementedParamType
|
|
|
32 |
*/
|
|
|
33 |
public function render(Node $node, ChildNodeRendererInterface $childRenderer)
|
|
|
34 |
{
|
|
|
35 |
TableSection::assertInstanceOf($node);
|
|
|
36 |
|
|
|
37 |
if (! $node->hasChildren()) {
|
|
|
38 |
return '';
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
$attrs = $node->data->get('attributes');
|
|
|
42 |
|
|
|
43 |
$separator = $childRenderer->getInnerSeparator();
|
|
|
44 |
|
|
|
45 |
$tag = $node->getType() === TableSection::TYPE_HEAD ? 'thead' : 'tbody';
|
|
|
46 |
|
|
|
47 |
return new HtmlElement($tag, $attrs, $separator . $childRenderer->renderNodes($node->children()) . $separator);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
public function getXmlTagName(Node $node): string
|
|
|
51 |
{
|
|
|
52 |
return 'table_section';
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
* @param TableSection $node
|
|
|
57 |
*
|
|
|
58 |
* @return array<string, scalar>
|
|
|
59 |
*
|
|
|
60 |
* @psalm-suppress MoreSpecificImplementedParamType
|
|
|
61 |
*/
|
|
|
62 |
public function getXmlAttributes(Node $node): array
|
|
|
63 |
{
|
|
|
64 |
TableSection::assertInstanceOf($node);
|
|
|
65 |
|
|
|
66 |
return [
|
|
|
67 |
'type' => $node->getType(),
|
|
|
68 |
];
|
|
|
69 |
}
|
|
|
70 |
}
|