1<?php
2
3/*
4 * This file is part of the clockoon/dokuwiki-commonmark-plugin package.
5 *
6 * (c) Sungbin Jeon <clockoon@gmail.com>
7 *
8 * Original code based on the followings:
9 * - CommonMark JS reference parser (https://bitly.com/commonmark-js) (c) John MacFarlane
10 * - league/commonmark (https://github.com/thephpleague/commonmark) (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 DokuWiki\Plugin\Commonmark\Extension\Renderer\Inline;
17
18use League\CommonMark\Renderer\NodeRendererInterface;
19use League\CommonMark\Renderer\ChildNodeRendererInterface;
20use League\CommonMark\Node\Inline\Newline;
21use League\CommonMark\Node\Node;
22
23final class NewlineRenderer implements NodeRendererInterface
24{
25    /**
26     * @param Newline                  $inline
27     * @param ChildNodeRendererInterface $DWRenderer
28     *
29     * @return HtmlElement|string
30     */
31    public function render(Node $node, ChildNodeRendererInterface $DWRenderer)
32    {
33        Newline::assertInstanceOf($node);
34
35        if ($node->getType() === Newline::HARDBREAK) {
36            return "\\\\ ";
37        }
38
39        return $DWRenderer->getOption('soft_break', "\n");
40    }
41}
42