Conditions | 4 |
Paths | 6 |
Total Lines | 26 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 4.074 |
Changes | 0 |
1 | <?php |
||
14 | 21 | public function convert(ElementInterface $element) |
|
15 | { |
||
16 | 21 | $value = $element->getValue(); |
|
17 | |||
18 | 21 | $markdown = ''; |
|
19 | |||
20 | /* |
||
21 | * > ocurrences must be escaped, otherwise instead of rendering p tags as paragraph blocks, |
||
22 | * the > will make them appear as a blockquote. |
||
23 | * To achieve this, the content of the paragraph must be exploded and then each line must be check |
||
24 | * if the first character (sans blank space) is a > |
||
25 | */ |
||
26 | |||
27 | 21 | $lines = explode("\n", $value); |
|
28 | 21 | foreach ($lines as $line) { |
|
29 | 21 | if (strpos(ltrim($line), '>') === 0) { |
|
30 | // Found a > char, escaping it |
||
31 | $markdown .= '\\' . ltrim($line); |
||
32 | } else { |
||
33 | 21 | $markdown .= $line; |
|
34 | } |
||
35 | 21 | $markdown .= "\n"; |
|
36 | 21 | } |
|
37 | |||
38 | 21 | return trim($markdown) !== '' ? rtrim($markdown) . "\n\n" : ''; |
|
39 | } |
||
40 | |||
49 |