1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the league/commonmark package. |
||
7 | * |
||
8 | * (c) Colin O'Dell <[email protected]> |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace League\CommonMark\Parser; |
||
15 | |||
16 | use League\CommonMark\Parser\Block\BlockContinueParserInterface; |
||
17 | use League\CommonMark\Parser\Block\ParagraphParser; |
||
18 | |||
19 | /** |
||
20 | * @internal You should rely on the interface instead |
||
21 | */ |
||
22 | final class MarkdownParserState implements MarkdownParserStateInterface |
||
23 | { |
||
24 | /** @psalm-readonly */ |
||
25 | private BlockContinueParserInterface $activeBlockParser; |
||
26 | |||
27 | /** @psalm-readonly */ |
||
28 | private BlockContinueParserInterface $lastMatchedBlockParser; |
||
29 | |||
30 | 2304 | public function __construct(BlockContinueParserInterface $activeBlockParser, BlockContinueParserInterface $lastMatchedBlockParser) |
|
31 | { |
||
32 | 2304 | $this->activeBlockParser = $activeBlockParser; |
|
33 | 2304 | $this->lastMatchedBlockParser = $lastMatchedBlockParser; |
|
34 | } |
||
35 | |||
36 | 208 | public function getActiveBlockParser(): BlockContinueParserInterface |
|
37 | { |
||
38 | 208 | return $this->activeBlockParser; |
|
39 | } |
||
40 | |||
41 | 302 | public function getLastMatchedBlockParser(): BlockContinueParserInterface |
|
42 | { |
||
43 | 302 | return $this->lastMatchedBlockParser; |
|
44 | } |
||
45 | |||
46 | 1318 | public function getParagraphContent(): ?string |
|
47 | { |
||
48 | 1318 | if (! $this->lastMatchedBlockParser instanceof ParagraphParser) { |
|
49 | 1234 | return null; |
|
50 | } |
||
51 | |||
52 | 276 | $paragraphParser = $this->lastMatchedBlockParser; |
|
53 | 276 | $content = $paragraphParser->getContentString(); |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
54 | |||
55 | 276 | return $content === '' ? null : $content; |
|
56 | } |
||
57 | } |
||
58 |