]> git.mxchange.org Git - friendica.git/blob - vendor/league/html-to-markdown/src/Converter/EmphasisConverter.php
Merge branch 'develop' into rewrites/coding-convention-split2-1-2
[friendica.git] / vendor / league / html-to-markdown / src / Converter / EmphasisConverter.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 EmphasisConverter implements ConverterInterface, ConfigurationAwareInterface
10 {
11     /**
12      * @var Configuration
13      */
14     protected $config;
15
16     /**
17      * @param Configuration $config
18      */
19     public function setConfig(Configuration $config)
20     {
21         $this->config = $config;
22     }
23
24     /**
25      * @param ElementInterface $element
26      *
27      * @return string
28      */
29     public function convert(ElementInterface $element)
30     {
31         $tag = $element->getTagName();
32         $value = $element->getValue();
33
34         if (!trim($value)) {
35             return '';
36         }
37
38         if ($tag === 'i' || $tag === 'em') {
39             $style = $this->config->getOption('italic_style');
40         } else {
41             $style = $this->config->getOption('bold_style');
42         }
43
44         $prefix = ltrim($value) !== $value ? ' ' : '';
45         $suffix = rtrim($value) !== $value ? ' ' : '';
46
47         return $prefix . $style . trim($value) . $style . $suffix;
48     }
49
50     /**
51      * @return string[]
52      */
53     public function getSupportedTags()
54     {
55         return array('em', 'i', 'strong', 'b');
56     }
57 }