1<?php 2 3/* 4 * This file is part of the league/commonmark package. 5 * 6 * (c) Colin O'Dell <colinodell@gmail.com> 7 * 8 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) 9 * - (c) John MacFarlane 10 * 11 * For the full copyright and license information, please view the LICENSE 12 * file that was distributed with this source code. 13 */ 14 15namespace League\CommonMark\Inline\Renderer; 16 17use League\CommonMark\ElementRendererInterface; 18use League\CommonMark\EnvironmentInterface; 19use League\CommonMark\Inline\Element\AbstractInline; 20use League\CommonMark\Inline\Element\HtmlInline; 21use League\CommonMark\Util\ConfigurationAwareInterface; 22use League\CommonMark\Util\ConfigurationInterface; 23 24final class HtmlInlineRenderer implements InlineRendererInterface, ConfigurationAwareInterface 25{ 26 /** 27 * @var ConfigurationInterface 28 */ 29 protected $config; 30 31 /** 32 * @param HtmlInline $inline 33 * @param ElementRendererInterface $htmlRenderer 34 * 35 * @return string 36 */ 37 public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer) 38 { 39 if (!($inline instanceof HtmlInline)) { 40 throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline)); 41 } 42 43 if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_STRIP) { 44 return ''; 45 } 46 47 if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_ESCAPE) { 48 return \htmlspecialchars($inline->getContent(), \ENT_NOQUOTES); 49 } 50 51 return $inline->getContent(); 52 } 53 54 public function setConfiguration(ConfigurationInterface $configuration) 55 { 56 $this->config = $configuration; 57 } 58} 59