1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the league/commonmark package. |
5
|
|
|
* |
6
|
|
|
* (c) Colin O'Dell <[email protected]> |
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
|
|
|
|
15
|
|
|
namespace League\CommonMark\Block\Element; |
16
|
|
|
|
17
|
|
|
use League\CommonMark\Cursor; |
18
|
|
|
|
19
|
|
|
class ListItem extends AbstractBlock |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var ListData |
23
|
|
|
*/ |
24
|
|
|
protected $listData; |
25
|
|
|
|
26
|
240 |
|
public function __construct(ListData $listData) |
27
|
|
|
{ |
28
|
240 |
|
parent::__construct(); |
29
|
|
|
|
30
|
240 |
|
$this->listData = $listData; |
31
|
240 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Returns true if this block can contain the given block as a child node |
35
|
|
|
* |
36
|
|
|
* @param AbstractBlock $block |
37
|
|
|
* |
38
|
|
|
* @return bool |
39
|
|
|
*/ |
40
|
231 |
|
public function canContain(AbstractBlock $block) |
41
|
|
|
{ |
42
|
231 |
|
return true; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Returns true if block type can accept lines of text |
47
|
|
|
* |
48
|
|
|
* @return bool |
49
|
|
|
*/ |
50
|
237 |
|
public function acceptsLines() |
51
|
|
|
{ |
52
|
237 |
|
return false; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Whether this is a code block |
57
|
|
|
* |
58
|
|
|
* @return bool |
59
|
|
|
*/ |
60
|
237 |
|
public function isCode() |
61
|
|
|
{ |
62
|
237 |
|
return false; |
63
|
|
|
} |
64
|
|
|
|
65
|
204 |
|
public function matchesNextLine(Cursor $cursor) |
66
|
|
|
{ |
67
|
204 |
|
if ($cursor->isBlank()) { |
68
|
120 |
|
if ($this->firstChild === null) { |
69
|
6 |
|
return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
114 |
|
$cursor->advanceToNextNonSpaceOrTab(); |
73
|
201 |
|
} elseif ($cursor->getIndent() >= $this->listData->markerOffset + $this->listData->padding) { |
74
|
120 |
|
$cursor->advanceBy($this->listData->markerOffset + $this->listData->padding, true); |
75
|
80 |
|
} else { |
76
|
120 |
|
return false; |
77
|
|
|
} |
78
|
|
|
|
79
|
144 |
|
return true; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param Cursor $cursor |
84
|
|
|
* @param int $currentLineNumber |
85
|
|
|
* |
86
|
|
|
* @return bool |
87
|
|
|
*/ |
88
|
228 |
|
public function shouldLastLineBeBlank(Cursor $cursor, $currentLineNumber) |
89
|
|
|
{ |
90
|
228 |
|
return $cursor->isBlank() && $this->startLine < $currentLineNumber; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|