1<?php 2 3/* 4 * This file is part of the league/commonmark package. 5 * 6 * (c) Colin O'Dell <colinodell@gmail.com> 7 * 8 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) 9 * - (c) John MacFarlane 10 * 11 * For the full copyright and license information, please view the LICENSE 12 * file that was distributed with this source code. 13 */ 14 15namespace League\CommonMark\Block\Element; 16 17use League\CommonMark\Cursor; 18 19/** 20 * @method children() AbstractBlock[] 21 */ 22class ListItem extends AbstractBlock 23{ 24 /** 25 * @var ListData 26 */ 27 protected $listData; 28 29 public function __construct(ListData $listData) 30 { 31 $this->listData = $listData; 32 } 33 34 /** 35 * @return ListData 36 */ 37 public function getListData(): ListData 38 { 39 return $this->listData; 40 } 41 42 public function canContain(AbstractBlock $block): bool 43 { 44 return true; 45 } 46 47 public function isCode(): bool 48 { 49 return false; 50 } 51 52 public function matchesNextLine(Cursor $cursor): bool 53 { 54 if ($cursor->isBlank()) { 55 if ($this->firstChild === null) { 56 return false; 57 } 58 59 $cursor->advanceToNextNonSpaceOrTab(); 60 } elseif ($cursor->getIndent() >= $this->listData->markerOffset + $this->listData->padding) { 61 $cursor->advanceBy($this->listData->markerOffset + $this->listData->padding, true); 62 } else { 63 return false; 64 } 65 66 return true; 67 } 68 69 public function shouldLastLineBeBlank(Cursor $cursor, int $currentLineNumber): bool 70 { 71 return $cursor->isBlank() && $this->startLine < $currentLineNumber; 72 } 73} 74