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