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