|
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; |
|
16
|
|
|
|
|
17
|
|
|
use League\CommonMark\Configuration\ConfigurationBuilderInterface; |
|
18
|
|
|
use League\CommonMark\Environment\EnvironmentBuilderInterface; |
|
19
|
|
|
use League\CommonMark\Event\DocumentParsedEvent; |
|
20
|
|
|
use League\CommonMark\Extension\ConfigurableExtensionInterface; |
|
21
|
|
|
use League\CommonMark\Extension\Footnote\Event\AnonymousFootnotesListener; |
|
22
|
|
|
use League\CommonMark\Extension\Footnote\Event\FixOrphanedFootnotesAndRefsListener; |
|
23
|
|
|
use League\CommonMark\Extension\Footnote\Event\GatherFootnotesListener; |
|
24
|
|
|
use League\CommonMark\Extension\Footnote\Event\NumberFootnotesListener; |
|
25
|
|
|
use League\CommonMark\Extension\Footnote\Node\Footnote; |
|
26
|
|
|
use League\CommonMark\Extension\Footnote\Node\FootnoteBackref; |
|
27
|
|
|
use League\CommonMark\Extension\Footnote\Node\FootnoteContainer; |
|
28
|
|
|
use League\CommonMark\Extension\Footnote\Node\FootnoteRef; |
|
29
|
|
|
use League\CommonMark\Extension\Footnote\Parser\AnonymousFootnoteRefParser; |
|
30
|
|
|
use League\CommonMark\Extension\Footnote\Parser\FootnoteRefParser; |
|
31
|
|
|
use League\CommonMark\Extension\Footnote\Parser\FootnoteStartParser; |
|
32
|
|
|
use League\CommonMark\Extension\Footnote\Renderer\FootnoteBackrefRenderer; |
|
33
|
|
|
use League\CommonMark\Extension\Footnote\Renderer\FootnoteContainerRenderer; |
|
34
|
|
|
use League\CommonMark\Extension\Footnote\Renderer\FootnoteRefRenderer; |
|
35
|
|
|
use League\CommonMark\Extension\Footnote\Renderer\FootnoteRenderer; |
|
36
|
|
|
use Nette\Schema\Expect; |
|
37
|
|
|
|
|
38
|
|
|
final class FootnoteExtension implements ConfigurableExtensionInterface |
|
39
|
|
|
{ |
|
40
|
150 |
|
public function configureSchema(ConfigurationBuilderInterface $builder): void |
|
41
|
|
|
{ |
|
42
|
150 |
|
$builder->addSchema('footnote', Expect::structure([ |
|
43
|
150 |
|
'backref_class' => Expect::string('footnote-backref'), |
|
44
|
150 |
|
'backref_symbol' => Expect::string('↩'), |
|
45
|
150 |
|
'container_add_hr' => Expect::bool(true), |
|
46
|
150 |
|
'container_class' => Expect::string('footnotes'), |
|
47
|
150 |
|
'ref_class' => Expect::string('footnote-ref'), |
|
48
|
150 |
|
'ref_id_prefix' => Expect::string('fnref:'), |
|
49
|
150 |
|
'footnote_class' => Expect::string('footnote'), |
|
50
|
150 |
|
'footnote_id_prefix' => Expect::string('fn:'), |
|
51
|
|
|
])); |
|
52
|
150 |
|
} |
|
53
|
|
|
|
|
54
|
105 |
|
public function register(EnvironmentBuilderInterface $environment): void |
|
55
|
|
|
{ |
|
56
|
105 |
|
$environment->addBlockStartParser(new FootnoteStartParser(), 51); |
|
57
|
105 |
|
$environment->addInlineParser(new AnonymousFootnoteRefParser(), 35); |
|
58
|
105 |
|
$environment->addInlineParser(new FootnoteRefParser(), 51); |
|
59
|
|
|
|
|
60
|
105 |
|
$environment->addRenderer(FootnoteContainer::class, new FootnoteContainerRenderer()); |
|
61
|
105 |
|
$environment->addRenderer(Footnote::class, new FootnoteRenderer()); |
|
62
|
105 |
|
$environment->addRenderer(FootnoteRef::class, new FootnoteRefRenderer()); |
|
63
|
105 |
|
$environment->addRenderer(FootnoteBackref::class, new FootnoteBackrefRenderer()); |
|
64
|
|
|
|
|
65
|
105 |
|
$environment->addEventListener(DocumentParsedEvent::class, [new AnonymousFootnotesListener(), 'onDocumentParsed'], 40); |
|
66
|
105 |
|
$environment->addEventListener(DocumentParsedEvent::class, [new FixOrphanedFootnotesAndRefsListener(), 'onDocumentParsed'], 30); |
|
67
|
105 |
|
$environment->addEventListener(DocumentParsedEvent::class, [new NumberFootnotesListener(), 'onDocumentParsed'], 20); |
|
68
|
105 |
|
$environment->addEventListener(DocumentParsedEvent::class, [new GatherFootnotesListener(), 'onDocumentParsed'], 10); |
|
69
|
105 |
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|