Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 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 <colinodell@gmail.com>
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\Block;
15
 
16
use League\CommonMark\Node\Block\Paragraph;
17
use League\CommonMark\Parser\Cursor;
18
use League\CommonMark\Parser\InlineParserEngineInterface;
19
use League\CommonMark\Reference\ReferenceInterface;
20
use League\CommonMark\Reference\ReferenceParser;
21
 
22
final class ParagraphParser extends AbstractBlockContinueParser implements BlockContinueParserWithInlinesInterface
23
{
24
    /** @psalm-readonly */
25
    private Paragraph $block;
26
 
27
    /** @psalm-readonly */
28
    private ReferenceParser $referenceParser;
29
 
30
    public function __construct()
31
    {
32
        $this->block           = new Paragraph();
33
        $this->referenceParser = new ReferenceParser();
34
    }
35
 
36
    public function canHaveLazyContinuationLines(): bool
37
    {
38
        return true;
39
    }
40
 
41
    public function getBlock(): Paragraph
42
    {
43
        return $this->block;
44
    }
45
 
46
    public function tryContinue(Cursor $cursor, BlockContinueParserInterface $activeBlockParser): ?BlockContinue
47
    {
48
        if ($cursor->isBlank()) {
49
            return BlockContinue::none();
50
        }
51
 
52
        return BlockContinue::at($cursor);
53
    }
54
 
55
    public function addLine(string $line): void
56
    {
57
        $this->referenceParser->parse($line);
58
    }
59
 
60
    public function closeBlock(): void
61
    {
62
        if ($this->referenceParser->hasReferences() && $this->referenceParser->getParagraphContent() === '') {
63
            $this->block->detach();
64
        }
65
    }
66
 
67
    public function parseInlines(InlineParserEngineInterface $inlineParser): void
68
    {
69
        $content = $this->getContentString();
70
        if ($content !== '') {
71
            $inlineParser->parse($content, $this->block);
72
        }
73
    }
74
 
75
    public function getContentString(): string
76
    {
77
        return $this->referenceParser->getParagraphContent();
78
    }
79
 
80
    /**
81
     * @return ReferenceInterface[]
82
     */
83
    public function getReferences(): iterable
84
    {
85
        return $this->referenceParser->getReferences();
86
    }
87
}