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\HtmlInline; 19use League\CommonMark\Node\Node; 20use League\CommonMark\Renderer\ChildNodeRendererInterface; 21use League\CommonMark\Renderer\NodeRendererInterface; 22use League\CommonMark\Util\HtmlFilter; 23use League\CommonMark\Xml\XmlNodeRendererInterface; 24use League\Config\ConfigurationAwareInterface; 25use League\Config\ConfigurationInterface; 26 27final class HtmlInlineRenderer implements NodeRendererInterface, ConfigurationAwareInterface 28{ 29 /** 30 * @var ConfigurationInterface 31 */ 32 private ConfigurationInterface $config; 33 34 /** 35 * @param HtmlInline $inline 36 * @param ChildNodeRendererInterface $DWRenderer 37 * 38 * @return string 39 */ 40 public function render(Node $node, ChildNodeRendererInterface $DWRenderer): string 41 { 42 HtmlInline::assertInstanceOf($node); 43 44 if ($this->config->get('html_input') === HtmlFilter::STRIP) { 45 return ''; 46 } 47 48 if ($this->config->get('html_input') === HtmlFilter::ESCAPE) { 49 return \htmlspecialchars($node->getLiteral(), \ENT_NOQUOTES); 50 } 51 52 return $node->getLiteral(); 53 } 54 55 public function setConfiguration(ConfigurationInterface $configuration): void 56 { 57 $this->config = $configuration; 58 } 59} 60