1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the league/commonmark package. |
5
|
|
|
* |
6
|
|
|
* (c) Colin O'Dell <[email protected]> |
7
|
|
|
* (c) Rezo Zero / Ambroise Maupate |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
declare(strict_types=1); |
14
|
|
|
|
15
|
|
|
namespace League\CommonMark\Extension\Footnote\Renderer; |
16
|
|
|
|
17
|
|
|
use League\CommonMark\Block\Element\AbstractBlock; |
18
|
|
|
use League\CommonMark\Block\Renderer\BlockRendererInterface; |
19
|
|
|
use League\CommonMark\ElementRendererInterface; |
20
|
|
|
use League\CommonMark\Extension\Footnote\Node\FootnoteContainer; |
21
|
|
|
use League\CommonMark\HtmlElement; |
22
|
|
|
use League\CommonMark\Util\ConfigurationAwareInterface; |
23
|
|
|
use League\CommonMark\Util\ConfigurationInterface; |
24
|
|
|
|
25
|
|
|
final class FootnoteContainerRenderer implements BlockRendererInterface, ConfigurationAwareInterface |
26
|
|
|
{ |
27
|
|
|
/** @var ConfigurationInterface */ |
28
|
|
|
private $config; |
29
|
|
|
|
30
|
48 |
|
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false) |
31
|
|
|
{ |
32
|
48 |
|
if (!($block instanceof FootnoteContainer)) { |
33
|
|
|
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block)); |
34
|
|
|
} |
35
|
|
|
|
36
|
48 |
|
$attrs = $block->getData('attributes', []); |
37
|
48 |
|
$attrs['class'] = $attrs['class'] ?? $this->config->get('footnote/container_class', 'footnotes'); |
38
|
48 |
|
$attrs['role'] = 'doc-endnotes'; |
39
|
|
|
|
40
|
48 |
|
$contents = new HtmlElement('ol', [], $htmlRenderer->renderBlocks($block->children())); |
41
|
48 |
|
if ($this->config->get('footnote/container_add_hr', true)) { |
42
|
45 |
|
$contents = [new HtmlElement('hr', [], null, true), $contents]; |
43
|
|
|
} |
44
|
|
|
|
45
|
48 |
|
return new HtmlElement('div', $attrs, $contents); |
46
|
|
|
} |
47
|
|
|
|
48
|
54 |
|
public function setConfiguration(ConfigurationInterface $configuration) |
49
|
|
|
{ |
50
|
54 |
|
$this->config = $configuration; |
51
|
54 |
|
} |
52
|
|
|
} |
53
|
|
|
|