Conditions | 4 |
Paths | 4 |
Total Lines | 23 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 4 |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
14 | 6 | public function convert(ElementInterface $element) |
|
15 | { |
||
16 | // If parent is an ol, use numbers, otherwise, use dashes |
||
17 | 6 | $list_type = $element->getParent()->getTagName(); |
|
18 | 6 | $value = $element->getValue(); |
|
19 | |||
20 | // Add spaces to start for nested list items |
||
21 | 6 | $level = $element->getListItemLevel($element); |
|
22 | 6 | $prefix = str_repeat(' ', $level); |
|
23 | // If list item is the first in a nested list, add a newline before it |
||
24 | 6 | if ($level > 0 && $element->getSiblingPosition() === 1) { |
|
25 | 3 | $prefix = "\n" . $prefix; |
|
26 | 3 | } |
|
27 | |||
28 | 6 | if ($list_type === 'ul') { |
|
29 | 6 | $markdown = $prefix . '- ' . trim($value) . "\n"; |
|
30 | 6 | } else { |
|
31 | 6 | $number = $element->getSiblingPosition(); |
|
32 | 6 | $markdown = $prefix . $number . '. ' . trim($value) . "\n"; |
|
33 | } |
||
34 | |||
35 | 6 | return $markdown; |
|
36 | } |
||
37 | |||
46 |