Conditions | 6 |
Paths | 6 |
Total Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 6 |
Changes | 0 |
1 | <?php |
||
14 | 66 | public function convert(ElementInterface $element) |
|
15 | { |
||
16 | 66 | $markdown = $element->getValue(); |
|
17 | |||
18 | // Remove leftover \n at the beginning of the line |
||
19 | 66 | $markdown = ltrim($markdown, "\n"); |
|
20 | |||
21 | // Replace sequences of invisible characters with spaces |
||
22 | 66 | $markdown = preg_replace('~\s+~u', ' ', $markdown); |
|
23 | |||
24 | // Escape the following characters: '*', '_', '[', ']' and '\' |
||
25 | 66 | if ($element->getParent() && $element->getParent()->getTagName() !== 'div') { |
|
26 | 66 | $markdown = preg_replace('~([*_\\[\\]\\\\])~u', '\\\\$1', $markdown); |
|
27 | 44 | } |
|
28 | |||
29 | 66 | $markdown = preg_replace('~^#~u', '\\\\#', $markdown); |
|
30 | |||
31 | 66 | if ($markdown === ' ') { |
|
32 | 9 | $next = $element->getNext(); |
|
33 | 9 | if (!$next || $next->isBlock()) { |
|
34 | 3 | $markdown = ''; |
|
35 | 2 | } |
|
36 | 6 | } |
|
37 | |||
38 | 66 | return $markdown; |
|
39 | } |
||
40 | |||
49 |