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\Configuration\ConfigurationAwareInterface; |
18
|
|
|
use League\CommonMark\Configuration\ConfigurationInterface; |
19
|
|
|
use League\CommonMark\Extension\Footnote\Node\FootnoteBackref; |
20
|
|
|
use League\CommonMark\Node\Node; |
21
|
|
|
use League\CommonMark\Renderer\ChildNodeRendererInterface; |
22
|
|
|
use League\CommonMark\Renderer\NodeRendererInterface; |
23
|
|
|
use League\CommonMark\Util\HtmlElement; |
24
|
|
|
|
25
|
|
|
final class FootnoteBackrefRenderer implements NodeRendererInterface, ConfigurationAwareInterface |
26
|
|
|
{ |
27
|
|
|
/** @var ConfigurationInterface */ |
28
|
|
|
private $config; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritDoc} |
32
|
|
|
*/ |
33
|
45 |
|
public function render(Node $node, ChildNodeRendererInterface $childRenderer) |
34
|
|
|
{ |
35
|
45 |
|
if (! ($node instanceof FootnoteBackref)) { |
36
|
|
|
throw new \InvalidArgumentException('Incompatible node type: ' . \get_class($node)); |
37
|
|
|
} |
38
|
|
|
|
39
|
45 |
|
$attrs = $node->getData('attributes', []); |
40
|
|
|
|
41
|
45 |
|
$attrs['class'] = $attrs['class'] ?? $this->config->get('footnote/backref_class', 'footnote-backref'); |
42
|
45 |
|
$attrs['rev'] = 'footnote'; |
43
|
45 |
|
$attrs['href'] = \mb_strtolower($node->getReference()->getDestination()); |
44
|
45 |
|
$attrs['role'] = 'doc-backlink'; |
45
|
|
|
|
46
|
45 |
|
return ' ' . new HtmlElement('a', $attrs, '↩', true); |
47
|
|
|
} |
48
|
|
|
|
49
|
51 |
|
public function setConfiguration(ConfigurationInterface $configuration): void |
50
|
|
|
{ |
51
|
51 |
|
$this->config = $configuration; |
52
|
51 |
|
} |
53
|
|
|
} |
54
|
|
|
|