| 148 |
lars |
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 |
* 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 |
private Description $block;
|
|
|
26 |
|
|
|
27 |
private int $indentation;
|
|
|
28 |
|
|
|
29 |
public function __construct(bool $tight, int $indentation)
|
|
|
30 |
{
|
|
|
31 |
$this->block = new Description($tight);
|
|
|
32 |
$this->indentation = $indentation;
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
public function getBlock(): Description
|
|
|
36 |
{
|
|
|
37 |
return $this->block;
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
public function tryContinue(Cursor $cursor, BlockContinueParserInterface $activeBlockParser): ?BlockContinue
|
|
|
41 |
{
|
|
|
42 |
if ($cursor->isBlank()) {
|
|
|
43 |
if ($this->block->firstChild() === null) {
|
|
|
44 |
// Blank line after empty item
|
|
|
45 |
return BlockContinue::none();
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
$cursor->advanceToNextNonSpaceOrTab();
|
|
|
49 |
|
|
|
50 |
return BlockContinue::at($cursor);
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
if ($cursor->getIndent() >= $this->indentation) {
|
|
|
54 |
$cursor->advanceBy($this->indentation, true);
|
|
|
55 |
|
|
|
56 |
return BlockContinue::at($cursor);
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
return BlockContinue::none();
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
public function isContainer(): bool
|
|
|
63 |
{
|
|
|
64 |
return true;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
public function canContain(AbstractBlock $childBlock): bool
|
|
|
68 |
{
|
|
|
69 |
return true;
|
|
|
70 |
}
|
|
|
71 |
}
|