]> git.mxchange.org Git - friendica.git/blob - vendor/league/html-to-markdown/src/Converter/DefaultConverter.php
Move HTML to Markdown library to Composer
[friendica.git] / vendor / league / html-to-markdown / src / Converter / DefaultConverter.php
1 <?php
2
3 namespace League\HTMLToMarkdown\Converter;
4
5 use League\HTMLToMarkdown\Configuration;
6 use League\HTMLToMarkdown\ConfigurationAwareInterface;
7 use League\HTMLToMarkdown\ElementInterface;
8
9 class DefaultConverter implements ConverterInterface, ConfigurationAwareInterface
10 {
11     const DEFAULT_CONVERTER = '_default';
12
13     /**
14      * @var Configuration
15      */
16     protected $config;
17
18     /**
19      * @param Configuration $config
20      */
21     public function setConfig(Configuration $config)
22     {
23         $this->config = $config;
24     }
25
26     /**
27      * @param ElementInterface $element
28      *
29      * @return string
30      */
31     public function convert(ElementInterface $element)
32     {
33         // If strip_tags is false (the default), preserve tags that don't have Markdown equivalents,
34         // such as <span> nodes on their own. C14N() canonicalizes the node to a string.
35         // See: http://www.php.net/manual/en/domnode.c14n.php
36         if ($this->config->getOption('strip_tags', false)) {
37             return $element->getValue();
38         }
39
40         return html_entity_decode($element->getChildrenAsString());
41     }
42
43     /**
44      * @return string[]
45      */
46     public function getSupportedTags()
47     {
48         return array(self::DEFAULT_CONVERTER);
49     }
50 }