|
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\Delimiter; |
|
16
|
|
|
|
|
17
|
|
|
use League\CommonMark\Inline\Element\AbstractStringContainer; |
|
18
|
|
|
|
|
19
|
|
|
final class Delimiter |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
private $char; |
|
23
|
|
|
|
|
24
|
|
|
/** @var int */ |
|
25
|
|
|
private $length; |
|
26
|
|
|
|
|
27
|
|
|
/** @var int */ |
|
28
|
|
|
private $originalLength; |
|
29
|
|
|
|
|
30
|
|
|
/** @var AbstractStringContainer */ |
|
31
|
|
|
private $inlineNode; |
|
32
|
|
|
|
|
33
|
|
|
/** @var Delimiter|null */ |
|
34
|
|
|
private $previous; |
|
35
|
|
|
|
|
36
|
|
|
/** @var Delimiter|null */ |
|
37
|
|
|
private $next; |
|
38
|
|
|
|
|
39
|
|
|
/** @var bool */ |
|
40
|
|
|
private $canOpen; |
|
41
|
|
|
|
|
42
|
|
|
/** @var bool */ |
|
43
|
|
|
private $canClose; |
|
44
|
|
|
|
|
45
|
|
|
/** @var bool */ |
|
46
|
|
|
private $active; |
|
47
|
|
|
|
|
48
|
|
|
/** @var int|null */ |
|
49
|
|
|
private $index; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param string $char |
|
53
|
|
|
* @param int $numDelims |
|
54
|
|
|
* @param AbstractStringContainer $node |
|
55
|
|
|
* @param bool $canOpen |
|
56
|
|
|
* @param bool $canClose |
|
57
|
|
|
* @param int|null $index |
|
58
|
|
|
*/ |
|
59
|
1020 |
|
public function __construct(string $char, int $numDelims, AbstractStringContainer $node, bool $canOpen, bool $canClose, ?int $index = null) |
|
60
|
|
|
{ |
|
61
|
1020 |
|
$this->char = $char; |
|
62
|
1020 |
|
$this->length = $numDelims; |
|
63
|
1020 |
|
$this->originalLength = $numDelims; |
|
64
|
1020 |
|
$this->inlineNode = $node; |
|
65
|
1020 |
|
$this->canOpen = $canOpen; |
|
66
|
1020 |
|
$this->canClose = $canClose; |
|
67
|
1020 |
|
$this->active = true; |
|
68
|
1020 |
|
$this->index = $index; |
|
69
|
1020 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return bool |
|
73
|
|
|
*/ |
|
74
|
924 |
|
public function canClose(): bool |
|
75
|
|
|
{ |
|
76
|
924 |
|
return $this->canClose; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param bool $canClose |
|
81
|
|
|
* |
|
82
|
|
|
* @return $this |
|
83
|
|
|
*/ |
|
84
|
3 |
|
public function setCanClose(bool $canClose) |
|
85
|
|
|
{ |
|
86
|
3 |
|
$this->canClose = $canClose; |
|
87
|
|
|
|
|
88
|
3 |
|
return $this; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return bool |
|
93
|
|
|
*/ |
|
94
|
501 |
|
public function canOpen(): bool |
|
95
|
|
|
{ |
|
96
|
501 |
|
return $this->canOpen; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param bool $canOpen |
|
101
|
|
|
* |
|
102
|
|
|
* @return $this |
|
103
|
|
|
*/ |
|
104
|
3 |
|
public function setCanOpen(bool $canOpen) |
|
105
|
|
|
{ |
|
106
|
3 |
|
$this->canOpen = $canOpen; |
|
107
|
|
|
|
|
108
|
3 |
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return bool |
|
113
|
|
|
*/ |
|
114
|
426 |
|
public function isActive(): bool |
|
115
|
|
|
{ |
|
116
|
426 |
|
return $this->active; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param bool $active |
|
121
|
|
|
* |
|
122
|
|
|
* @return $this |
|
123
|
|
|
*/ |
|
124
|
27 |
|
public function setActive(bool $active) |
|
125
|
|
|
{ |
|
126
|
27 |
|
$this->active = $active; |
|
127
|
|
|
|
|
128
|
27 |
|
return $this; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @return string |
|
133
|
|
|
*/ |
|
134
|
996 |
|
public function getChar(): string |
|
135
|
|
|
{ |
|
136
|
996 |
|
return $this->char; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @param string $char |
|
141
|
|
|
* |
|
142
|
|
|
* @return $this |
|
143
|
|
|
*/ |
|
144
|
3 |
|
public function setChar(string $char) |
|
145
|
|
|
{ |
|
146
|
3 |
|
$this->char = $char; |
|
147
|
|
|
|
|
148
|
3 |
|
return $this; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @return int|null |
|
153
|
|
|
*/ |
|
154
|
291 |
|
public function getIndex(): ?int |
|
155
|
|
|
{ |
|
156
|
291 |
|
return $this->index; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @param int|null $index |
|
161
|
|
|
* |
|
162
|
|
|
* @return $this |
|
163
|
|
|
*/ |
|
164
|
3 |
|
public function setIndex(?int $index) |
|
165
|
|
|
{ |
|
166
|
3 |
|
$this->index = $index; |
|
167
|
|
|
|
|
168
|
3 |
|
return $this; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @return Delimiter|null |
|
173
|
|
|
*/ |
|
174
|
993 |
|
public function getNext(): ?self |
|
175
|
|
|
{ |
|
176
|
993 |
|
return $this->next; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @param Delimiter|null $next |
|
181
|
|
|
* |
|
182
|
|
|
* @return $this |
|
183
|
|
|
*/ |
|
184
|
600 |
|
public function setNext(?self $next) |
|
185
|
|
|
{ |
|
186
|
600 |
|
$this->next = $next; |
|
187
|
|
|
|
|
188
|
600 |
|
return $this; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @return int |
|
193
|
|
|
*/ |
|
194
|
420 |
|
public function getLength(): int |
|
195
|
|
|
{ |
|
196
|
420 |
|
return $this->length; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @param int $length |
|
201
|
|
|
* |
|
202
|
|
|
* @return $this |
|
203
|
|
|
*/ |
|
204
|
417 |
|
public function setLength(int $length) |
|
205
|
|
|
{ |
|
206
|
417 |
|
$this->length = $length; |
|
207
|
|
|
|
|
208
|
417 |
|
return $this; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @return int |
|
213
|
|
|
*/ |
|
214
|
66 |
|
public function getOriginalLength(): int |
|
215
|
|
|
{ |
|
216
|
66 |
|
return $this->originalLength; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @return AbstractStringContainer |
|
221
|
|
|
*/ |
|
222
|
717 |
|
public function getInlineNode(): AbstractStringContainer |
|
223
|
|
|
{ |
|
224
|
717 |
|
return $this->inlineNode; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* @param AbstractStringContainer $node |
|
229
|
|
|
* |
|
230
|
|
|
* @return $this |
|
231
|
|
|
*/ |
|
232
|
3 |
|
public function setInlineNode(AbstractStringContainer $node) |
|
233
|
|
|
{ |
|
234
|
3 |
|
$this->inlineNode = $node; |
|
235
|
|
|
|
|
236
|
3 |
|
return $this; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* @return Delimiter|null |
|
241
|
|
|
*/ |
|
242
|
993 |
|
public function getPrevious(): ?self |
|
243
|
|
|
{ |
|
244
|
993 |
|
return $this->previous; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @param Delimiter|null $previous |
|
249
|
|
|
* |
|
250
|
|
|
* @return $this |
|
251
|
|
|
*/ |
|
252
|
993 |
|
public function setPrevious(?self $previous) |
|
253
|
|
|
{ |
|
254
|
993 |
|
$this->previous = $previous; |
|
255
|
|
|
|
|
256
|
993 |
|
return $this; |
|
257
|
|
|
} |
|
258
|
|
|
} |
|
259
|
|
|
|