1<?php 2 3/** 4 * Created by IntelliJ IDEA. 5 * User: michael 6 * Date: 7/7/17 7 * Time: 4:10 PM 8 */ 9 10namespace dokuwiki\plugin\prosemirror\parser; 11 12class ListItemNode extends Node 13{ 14 protected $parent; 15 /** @var Node[] */ 16 protected $subnodes = []; 17 18 /** 19 * ListItemNode constructor. 20 * 21 * @param $data 22 * @param ListNode $parent 23 */ 24 public function __construct($data, Node $parent) 25 { 26 $this->parent = &$parent; 27 28 foreach ($data['content'] as $node) { 29 if ($node['type'] === 'list_content') { 30 foreach ($node['content'] as $subnode) { 31 $this->subnodes[] = self::getSubNode($subnode, $this); 32 } 33 continue; 34 } 35 36 $this->subnodes[] = self::getSubNode($node, $this); 37 } 38 } 39 40 public function toSyntax() 41 { 42 $lines = []; 43 foreach ($this->subnodes as $node) { 44 /* 45 * only sublists may start with a linebreak, other blocks, like <code> must not have a linebreak before them 46 * or DokuWiki will interprete this as a new block altogether, instead as something that is part of the 47 * current <li> 48 */ 49 $prefixLinebreak = ''; 50 if ($node instanceof ListNode) { 51 $prefixLinebreak = "\n"; 52 } 53 $lines[] = $prefixLinebreak . $node->toSyntax(); 54 } 55 return implode("", $lines); 56 } 57 58 public function getDepth() 59 { 60 return $this->parent->getDepth(); 61 } 62} 63