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