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\Block\Element; |
16
|
|
|
|
17
|
|
|
use League\CommonMark\ContextInterface; |
18
|
|
|
use League\CommonMark\Cursor; |
19
|
|
|
|
20
|
|
|
class Heading extends AbstractStringContainerBlock implements InlineContainerInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var int |
24
|
|
|
*/ |
25
|
|
|
protected $level; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param int $level |
29
|
|
|
* @param string|string[] $contents |
30
|
|
|
*/ |
31
|
159 |
|
public function __construct(int $level, $contents) |
32
|
|
|
{ |
33
|
159 |
|
parent::__construct(); |
34
|
|
|
|
35
|
159 |
|
$this->level = $level; |
36
|
|
|
|
37
|
159 |
|
if (!\is_array($contents)) { |
38
|
111 |
|
$contents = [$contents]; |
39
|
|
|
} |
40
|
|
|
|
41
|
159 |
|
foreach ($contents as $line) { |
42
|
159 |
|
$this->addLine($line); |
43
|
|
|
} |
44
|
159 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return int |
48
|
|
|
*/ |
49
|
150 |
|
public function getLevel(): int |
50
|
|
|
{ |
51
|
150 |
|
return $this->level; |
52
|
|
|
} |
53
|
|
|
|
54
|
129 |
|
public function finalize(ContextInterface $context, int $endLineNumber) |
55
|
|
|
{ |
56
|
129 |
|
parent::finalize($context, $endLineNumber); |
57
|
|
|
|
58
|
129 |
|
$this->finalStringContents = \implode("\n", $this->strings->toArray()); |
59
|
129 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns true if this block can contain the given block as a child node |
63
|
|
|
* |
64
|
|
|
* @param AbstractBlock $block |
65
|
|
|
* |
66
|
|
|
* @return bool |
67
|
|
|
*/ |
68
|
3 |
|
public function canContain(AbstractBlock $block): bool |
69
|
|
|
{ |
70
|
3 |
|
return false; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Whether this is a code block |
75
|
|
|
* |
76
|
|
|
* @return bool |
77
|
|
|
*/ |
78
|
3 |
|
public function isCode(): bool |
79
|
|
|
{ |
80
|
3 |
|
return false; |
81
|
|
|
} |
82
|
|
|
|
83
|
81 |
|
public function matchesNextLine(Cursor $cursor): bool |
84
|
|
|
{ |
85
|
81 |
|
return false; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param ContextInterface $context |
90
|
|
|
* @param Cursor $cursor |
91
|
|
|
*/ |
92
|
129 |
|
public function handleRemainingContents(ContextInterface $context, Cursor $cursor) |
93
|
|
|
{ |
94
|
|
|
// nothing to do; contents were already added via the constructor. |
95
|
129 |
|
} |
96
|
|
|
} |
97
|
|
|
|