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\Extension\CommonMark\Node\Inline\Code;
19use League\CommonMark\Node\Node;
20use League\CommonMark\Renderer\ChildNodeRendererInterface;
21use League\CommonMark\Renderer\NodeRendererInterface;
22use League\CommonMark\Util\Xml;
23use League\CommonMark\Xml\XmlNodeRendererInterface;
24
25final class CodeRenderer implements NodeRendererInterface
26{
27    /**
28     * @param Code                     $inline
29     * @param ChildNodeRendererInterface $DWRenderer
30     *
31     * @return string
32     */
33    public function render(Node $node, ChildNodeRendererInterface $DWRenderer): string
34    {
35        Code::assertInstanceOf($node);
36
37        # Do not escape code; BELEIVE DOKUWIKI!
38        #return "''" . Xml::escape($inline->getContent()) . "''";
39        # add %% between inline content to block additional render
40        return "''%%" . $node->getLiteral() . "%%''";
41    }
42}
43