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\Block;
17
18use League\CommonMark\Node\Block\Paragraph;
19use League\CommonMark\Node\Block\TightBlockInterface;
20use League\CommonMark\Node\Node;
21use League\CommonMark\Renderer\ChildNodeRendererInterface;
22use League\CommonMark\Renderer\NodeRendererInterface;
23use League\CommonMark\Xml\XmlNodeRendererInterface;
24final class ParagraphRenderer implements NodeRendererInterface
25{
26    /**
27     * @param Paragraph                $block
28     * @param ElementRendererInterface $htmlRenderer
29     * @param bool                     $inTightList
30     *
31     * @return HtmlElement|string
32     */
33    public function render(Node $node, ChildNodeRendererInterface $DWRenderer)
34    {
35        Paragraph::assertInstanceOf($node);
36
37        $result = $DWRenderer->renderNodes($node->children());
38        $result = preg_replace('/\n/', ' ', $result); # remove unwanted newline for DW
39
40        return $result . $DWRenderer->getOption('inner_separator', "\n");;
41    }
42}
43