| Total Complexity | 9 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 12 | class ListNode extends Node |
||
| 13 | { |
||
| 14 | protected $parent; |
||
| 15 | /** @var string */ |
||
| 16 | protected $prefix; |
||
| 17 | /** @var ListItemNode[] */ |
||
| 18 | protected $listItemNodes = []; |
||
| 19 | |||
| 20 | protected $depth = 0; |
||
| 21 | |||
| 22 | public function __construct($data, Node $parent) |
||
| 23 | { |
||
| 24 | $this->parent = &$parent; |
||
| 25 | if (is_a($this->parent, 'dokuwiki\plugin\prosemirror\parser\ListItemNode')) { |
||
| 26 | $this->depth = $this->parent->getDepth() + 1; |
||
|
|
|||
| 27 | } |
||
| 28 | |||
| 29 | $this->prefix = $data['type'] == 'bullet_list' ? ' *' : ' -'; |
||
| 30 | |||
| 31 | foreach ($data['content'] as $listItemNode) { |
||
| 32 | $this->listItemNodes[] = new ListItemNode($listItemNode, $this); |
||
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | public function toSyntax() |
||
| 37 | { |
||
| 38 | $doc = ''; |
||
| 39 | |||
| 40 | foreach ($this->listItemNodes as $li) { |
||
| 41 | $liText = str_repeat(' ', $this->depth); |
||
| 42 | $liText .= $this->prefix; |
||
| 43 | $lines = $li->toSyntax(); |
||
| 44 | if (!empty($lines) && $lines[0] !== ' ') { |
||
| 45 | $liText .= ' '; |
||
| 46 | } |
||
| 47 | $liText .= $lines . "\n"; |
||
| 48 | $doc .= $liText; |
||
| 49 | } |
||
| 50 | return rtrim($doc); // blocks should __not__ end with a newline, parents must handle breaks between children |
||
| 51 | } |
||
| 52 | |||
| 53 | public function getDepth() |
||
| 56 | } |
||
| 57 | } |
||
| 58 |