DefaultConverter::setConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\HTMLToMarkdown\Converter;
6
7
use League\HTMLToMarkdown\Configuration;
8
use League\HTMLToMarkdown\ConfigurationAwareInterface;
9
use League\HTMLToMarkdown\ElementInterface;
10
11
class DefaultConverter implements ConverterInterface, ConfigurationAwareInterface
12
{
13
    public const DEFAULT_CONVERTER = '_default';
14
15
    /** @var Configuration */
16
    protected $config;
17
18
    public function setConfig(Configuration $config): void
19
    {
20
        $this->config = $config;
21 102
    }
22
23 102
    public function convert(ElementInterface $element): string
24 102
    {
25
        // If strip_tags is false (the default), preserve tags that don't have Markdown equivalents,
26
        // such as <span> nodes on their own. C14N() canonicalizes the node to a string.
27
        // See: http://www.php.net/manual/en/domnode.c14n.php
28
        if ($this->config->getOption('strip_tags', false)) {
29
            return $element->getValue();
30
        }
31 96
32
        $markdown = \html_entity_decode($element->getChildrenAsString());
33
34
        // Tables are only handled here if TableConverter is not used
35
        if ($element->getTagName() === 'table') {
36 96
            $markdown .= "\n\n";
37 18
        }
38
39
        return $markdown;
40 87
    }
41
42
    /**
43 87
     * @return string[]
44 3
     */
45 2
    public function getSupportedTags(): array
46
    {
47 87
        return [self::DEFAULT_CONVERTER];
48
    }
49
}
50