Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
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 TableCellRenderer implements NodeRendererInterface, XmlNodeRendererInterface
25
{
26
    /**
27
     * @param TableCell $node
28
     *
29
     * {@inheritDoc}
30
     *
31
     * @psalm-suppress MoreSpecificImplementedParamType
32
     */
33
    public function render(Node $node, ChildNodeRendererInterface $childRenderer): \Stringable
34
    {
35
        TableCell::assertInstanceOf($node);
36
 
37
        $attrs = $node->data->get('attributes');
38
 
39
        if ($node->getAlign() !== null) {
40
            $attrs['align'] = $node->getAlign();
41
        }
42
 
43
        $tag = $node->getType() === TableCell::TYPE_HEADER ? 'th' : 'td';
44
 
45
        return new HtmlElement($tag, $attrs, $childRenderer->renderNodes($node->children()));
46
    }
47
 
48
    public function getXmlTagName(Node $node): string
49
    {
50
        return 'table_cell';
51
    }
52
 
53
    /**
54
     * @param TableCell $node
55
     *
56
     * @return array<string, scalar>
57
     *
58
     * @psalm-suppress MoreSpecificImplementedParamType
59
     */
60
    public function getXmlAttributes(Node $node): array
61
    {
62
        TableCell::assertInstanceOf($node);
63
 
64
        $ret = ['type' => $node->getType()];
65
 
66
        if (($align = $node->getAlign()) !== null) {
67
            $ret['align'] = $align;
68
        }
69
 
70
        return $ret;
71
    }
72
}