Completed
Push — master ( 51616b...1810d3 )
by Colin
09:28 queued 06:40
created

src/Converter/TextConverter.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 '\'
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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 81
    public function getSupportedTags()
43
    {
44 81
        return array('#text');
45
    }
46
}
47