Subversion-Projekte lars-tiefland.laravel_shop

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 file is part of the league/commonmark package.
7
 *
8
 * (c) Colin O'Dell <colinodell@gmail.com>
9
 *
10
 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
11
 *  - (c) John MacFarlane
12
 *
13
 * For the full copyright and license information, please view the LICENSE
14
 * file that was distributed with this source code.
15
 */
16
 
17
namespace League\CommonMark\Renderer\Inline;
18
 
19
use League\CommonMark\Node\Inline\Newline;
20
use League\CommonMark\Node\Node;
21
use League\CommonMark\Renderer\ChildNodeRendererInterface;
22
use League\CommonMark\Renderer\NodeRendererInterface;
23
use League\CommonMark\Xml\XmlNodeRendererInterface;
24
use League\Config\ConfigurationAwareInterface;
25
use League\Config\ConfigurationInterface;
26
 
27
final class NewlineRenderer implements NodeRendererInterface, XmlNodeRendererInterface, ConfigurationAwareInterface
28
{
29
    /** @psalm-readonly-allow-private-mutation */
30
    private ConfigurationInterface $config;
31
 
32
    public function setConfiguration(ConfigurationInterface $configuration): void
33
    {
34
        $this->config = $configuration;
35
    }
36
 
37
    /**
38
     * @param Newline $node
39
     *
40
     * {@inheritDoc}
41
     *
42
     * @psalm-suppress MoreSpecificImplementedParamType
43
     */
44
    public function render(Node $node, ChildNodeRendererInterface $childRenderer): string
45
    {
46
        Newline::assertInstanceOf($node);
47
 
48
        if ($node->getType() === Newline::HARDBREAK) {
49
            return "<br />\n";
50
        }
51
 
52
        return $this->config->get('renderer/soft_break');
53
    }
54
 
55
    /**
56
     * @param Newline $node
57
     *
58
     * {@inheritDoc}
59
     *
60
     * @psalm-suppress MoreSpecificImplementedParamType
61
     */
62
    public function getXmlTagName(Node $node): string
63
    {
64
        Newline::assertInstanceOf($node);
65
 
66
        return $node->getType() === Newline::SOFTBREAK ? 'softbreak' : 'linebreak';
67
    }
68
 
69
    /**
70
     * {@inheritDoc}
71
     */
72
    public function getXmlAttributes(Node $node): array
73
    {
74
        return [];
75
    }
76
}