xref: /plugin/commonmark/src/Dokuwiki/Plugin/Commonmark/Extension/Renderer/Inline/NewlineRenderer.php (revision 0f46309a0ac22fdc4d1c91b56eae39d6eedaaf00)
18ec9a8f2SSungbin Jeon<?php
28ec9a8f2SSungbin Jeon
38ec9a8f2SSungbin Jeon/*
48ec9a8f2SSungbin Jeon * This file is part of the clockoon/dokuwiki-commonmark-plugin package.
58ec9a8f2SSungbin Jeon *
68ec9a8f2SSungbin Jeon * (c) Sungbin Jeon <clockoon@gmail.com>
78ec9a8f2SSungbin Jeon *
88ec9a8f2SSungbin Jeon * Original code based on the followings:
98ec9a8f2SSungbin Jeon * - CommonMark JS reference parser (https://bitly.com/commonmark-js) (c) John MacFarlane
108ec9a8f2SSungbin Jeon * - league/commonmark (https://github.com/thephpleague/commonmark) (c) Colin O'Dell <colinodell@gmail.com>
118ec9a8f2SSungbin Jeon *
128ec9a8f2SSungbin Jeon * For the full copyright and license information, please view the LICENSE
138ec9a8f2SSungbin Jeon * file that was distributed with this source code.
148ec9a8f2SSungbin Jeon */
158ec9a8f2SSungbin Jeon
168ec9a8f2SSungbin Jeonnamespace DokuWiki\Plugin\Commonmark\Extension\Renderer\Inline;
178ec9a8f2SSungbin Jeon
1894a075eeSSungbin Jeonuse League\CommonMark\Renderer\NodeRendererInterface;
19b0a36678SSungbin Jeonuse League\CommonMark\Renderer\ChildNodeRendererInterface;
20b0a36678SSungbin Jeonuse League\CommonMark\Node\Inline\Newline;
21b0a36678SSungbin Jeonuse League\CommonMark\Node\Node;
228ec9a8f2SSungbin Jeon
2394a075eeSSungbin Jeonfinal class NewlineRenderer implements NodeRendererInterface
248ec9a8f2SSungbin Jeon{
258ec9a8f2SSungbin Jeon    /**
268ec9a8f2SSungbin Jeon     * @param Newline                  $inline
27b0a36678SSungbin Jeon     * @param ChildNodeRendererInterface $DWRenderer
288ec9a8f2SSungbin Jeon     *
298ec9a8f2SSungbin Jeon     * @return HtmlElement|string
308ec9a8f2SSungbin Jeon     */
31b0a36678SSungbin Jeon    public function render(Node $node, ChildNodeRendererInterface $DWRenderer)
328ec9a8f2SSungbin Jeon    {
33b0a36678SSungbin Jeon        Newline::assertInstanceOf($node);
348ec9a8f2SSungbin Jeon
35b0a36678SSungbin Jeon        if ($node->getType() === Newline::HARDBREAK) {
36*0f46309aSChalix            return $DWRenderer->getOption('hard_break', true);
378ec9a8f2SSungbin Jeon        }
388ec9a8f2SSungbin Jeon
39c73f5e4dSChalix        return $DWRenderer->getOption('soft_break');
408ec9a8f2SSungbin Jeon    }
418ec9a8f2SSungbin Jeon}
42