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