|
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 AbstractBlock implements InlineContainerInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var int |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $level; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param int $level |
|
29
|
|
|
* @param string|string[] $contents |
|
30
|
|
|
*/ |
|
31
|
141 |
|
public function __construct($level, $contents) |
|
32
|
|
|
{ |
|
33
|
141 |
|
parent::__construct(); |
|
34
|
|
|
|
|
35
|
141 |
|
$this->level = $level; |
|
36
|
|
|
|
|
37
|
141 |
|
if (!is_array($contents)) { |
|
38
|
99 |
|
$contents = [$contents]; |
|
39
|
33 |
|
} |
|
40
|
|
|
|
|
41
|
141 |
|
foreach ($contents as $line) { |
|
42
|
141 |
|
$this->addLine($line); |
|
43
|
47 |
|
} |
|
44
|
141 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return int |
|
48
|
|
|
*/ |
|
49
|
141 |
|
public function getLevel() |
|
50
|
|
|
{ |
|
51
|
141 |
|
return $this->level; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
123 |
|
public function finalize(ContextInterface $context, $endLineNumber) |
|
55
|
|
|
{ |
|
56
|
123 |
|
parent::finalize($context, $endLineNumber); |
|
57
|
|
|
|
|
58
|
123 |
|
$this->finalStringContents = implode("\n", $this->getStrings()); |
|
59
|
123 |
|
} |
|
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
|
|
|
public function canContain(AbstractBlock $block) |
|
69
|
|
|
{ |
|
70
|
|
|
return false; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Returns true if block type can accept lines of text |
|
75
|
|
|
* |
|
76
|
|
|
* @return bool |
|
77
|
|
|
*/ |
|
78
|
141 |
|
public function acceptsLines() |
|
79
|
|
|
{ |
|
80
|
141 |
|
return true; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Whether this is a code block |
|
85
|
|
|
* |
|
86
|
|
|
* @return bool |
|
87
|
|
|
*/ |
|
88
|
|
|
public function isCode() |
|
89
|
|
|
{ |
|
90
|
|
|
return false; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
75 |
|
public function matchesNextLine(Cursor $cursor) |
|
94
|
|
|
{ |
|
95
|
75 |
|
return false; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param ContextInterface $context |
|
100
|
|
|
* @param Cursor $cursor |
|
101
|
|
|
*/ |
|
102
|
123 |
|
public function handleRemainingContents(ContextInterface $context, Cursor $cursor) |
|
103
|
|
|
{ |
|
104
|
|
|
// nothing to do; we already added the contents. |
|
105
|
123 |
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|