1<?php
2
3/*
4 * This file is part of the league/commonmark package.
5 *
6 * (c) Colin O'Dell <colinodell@gmail.com>
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
15namespace League\CommonMark\Block\Element;
16
17use League\CommonMark\ContextInterface;
18use League\CommonMark\Cursor;
19
20class 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    public function __construct(int $level, $contents)
32    {
33        parent::__construct();
34
35        $this->level = $level;
36
37        if (!\is_array($contents)) {
38            $contents = [$contents];
39        }
40
41        foreach ($contents as $line) {
42            $this->addLine($line);
43        }
44    }
45
46    /**
47     * @return int
48     */
49    public function getLevel(): int
50    {
51        return $this->level;
52    }
53
54    public function finalize(ContextInterface $context, int $endLineNumber)
55    {
56        parent::finalize($context, $endLineNumber);
57
58        $this->finalStringContents = \implode("\n", $this->strings->toArray());
59    }
60
61    public function canContain(AbstractBlock $block): bool
62    {
63        return false;
64    }
65
66    public function isCode(): bool
67    {
68        return false;
69    }
70
71    public function matchesNextLine(Cursor $cursor): bool
72    {
73        return false;
74    }
75
76    public function handleRemainingContents(ContextInterface $context, Cursor $cursor)
77    {
78        // nothing to do; contents were already added via the constructor.
79    }
80}
81