|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the league/commonmark package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Colin O'Dell <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace League\CommonMark\Extension\DescriptionList\Parser; |
|
15
|
|
|
|
|
16
|
|
|
use League\CommonMark\Extension\DescriptionList\Node\Description; |
|
17
|
|
|
use League\CommonMark\Node\Block\AbstractBlock; |
|
18
|
|
|
use League\CommonMark\Parser\Block\AbstractBlockContinueParser; |
|
19
|
|
|
use League\CommonMark\Parser\Block\BlockContinue; |
|
20
|
|
|
use League\CommonMark\Parser\Block\BlockContinueParserInterface; |
|
21
|
|
|
use League\CommonMark\Parser\Cursor; |
|
22
|
|
|
|
|
23
|
|
|
final class DescriptionContinueParser extends AbstractBlockContinueParser |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var Description */ |
|
26
|
|
|
private $block; |
|
27
|
|
|
|
|
28
|
|
|
/** @var int */ |
|
29
|
|
|
private $indentation; |
|
30
|
|
|
|
|
31
|
33 |
|
public function __construct(bool $tight, int $indentation) |
|
32
|
|
|
{ |
|
33
|
33 |
|
$this->block = new Description($tight); |
|
34
|
33 |
|
$this->indentation = $indentation; |
|
35
|
33 |
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @return Description |
|
39
|
|
|
*/ |
|
40
|
33 |
|
public function getBlock(): AbstractBlock |
|
41
|
|
|
{ |
|
42
|
33 |
|
return $this->block; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
33 |
|
public function tryContinue(Cursor $cursor, BlockContinueParserInterface $activeBlockParser): ?BlockContinue |
|
46
|
|
|
{ |
|
47
|
33 |
|
if ($cursor->isBlank()) { |
|
48
|
33 |
|
if ($this->block->firstChild() === null) { |
|
49
|
|
|
// Blank line after empty item |
|
50
|
|
|
return BlockContinue::none(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
33 |
|
$cursor->advanceToNextNonSpaceOrTab(); |
|
54
|
|
|
|
|
55
|
33 |
|
return BlockContinue::at($cursor); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
33 |
|
if ($cursor->getIndent() >= $this->indentation) { |
|
59
|
15 |
|
$cursor->advanceBy($this->indentation, true); |
|
60
|
|
|
|
|
61
|
15 |
|
return BlockContinue::at($cursor); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
33 |
|
return BlockContinue::none(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
33 |
|
public function isContainer(): bool |
|
68
|
|
|
{ |
|
69
|
33 |
|
return true; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
33 |
|
public function canContain(AbstractBlock $childBlock): bool |
|
73
|
|
|
{ |
|
74
|
33 |
|
return true; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|