Completed
Push — master ( ca9126...817989 )
by Colin
05:00 queued 15s
created

TextConverter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 40
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B convert() 0 24 4
A getSupportedTags() 0 4 1
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 57
    public function convert(ElementInterface $element)
15
    {
16 57
        $markdown = $element->getValue();
17
18
        // Remove leftover \n at the beginning of the line
19 57
        $markdown = ltrim($markdown, "\n");
20
21
        // Replace sequences of invisible characters with spaces
22 57
        $markdown = preg_replace('~\s+~u', ' ', $markdown);
23
24
        // Escape the following characters: '*', '_' and '\'
25 57
        $markdown = preg_replace('~([*_\\\\])~u', '\\\\$1', $markdown);
26
27 57
        $markdown = preg_replace('~^#~u', '\\\\#', $markdown);
28
29 57
        if ($markdown === ' ') {
30 9
            $next = $element->getNext();
31 9
            if (!$next || $next->isBlock()) {
32 3
                $markdown = '';
33 3
            }
34 9
        }
35
36 57
        return $markdown;
37
    }
38
39
    /**
40
     * @return string[]
41
     */
42 78
    public function getSupportedTags()
43
    {
44 78
        return array('#text');
45
    }
46
}
47