Completed
Pull Request — master (#100)
by
unknown
21:51 queued 19:53
created

TextConverter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 64.29%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 36
ccs 9
cts 14
cp 0.6429
rs 10
c 2
b 0
f 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSupportedTags() 0 4 1
A convert() 0 20 4
1
<?php
2
3
namespace League\HTMLToMarkdown\Converter;
4
5
use League\HTMLToMarkdown\ElementInterface;
6
7
class TextConverter implements ConverterInterface
8
{
9
    /**
10
     * @param ElementInterface $element
11
     *
12
     * @return string
13
     */
14 48
    public function convert(ElementInterface $element)
15
    {
16 48
        $value = $element->getValue();
17
18 48
        $markdown = preg_replace('~\s+~u', ' ', $value);
19
20
        //escape the following characters: '*', '_' and '\'
21 48
        $markdown = preg_replace('~([*_\\\\])~u', '\\\\$1', $markdown);
22
23 48
        $markdown = preg_replace('~^#~u', '\\\\#', $markdown);
24
25 48
        if ($markdown === ' ') {
26
            $next = $element->getNext();
27
            if (!$next || $next->isBlock()) {
28
                $markdown = '';
29
            }
30
        }
31
32 48
        return $markdown;
33
    }
34
35
    /**
36
     * @return string[]
37
     */
38 78
    public function getSupportedTags()
39
    {
40 78
        return array('#text');
41
    }
42
}
43