| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the league/commonmark package.
|
|
|
5 |
*
|
|
|
6 |
* (c) Colin O'Dell <colinodell@gmail.com>
|
|
|
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\Environment\EnvironmentBuilderInterface;
|
|
|
18 |
use League\CommonMark\Event\DocumentParsedEvent;
|
|
|
19 |
use League\CommonMark\Extension\ConfigurableExtensionInterface;
|
|
|
20 |
use League\CommonMark\Extension\Footnote\Event\AnonymousFootnotesListener;
|
|
|
21 |
use League\CommonMark\Extension\Footnote\Event\FixOrphanedFootnotesAndRefsListener;
|
|
|
22 |
use League\CommonMark\Extension\Footnote\Event\GatherFootnotesListener;
|
|
|
23 |
use League\CommonMark\Extension\Footnote\Event\NumberFootnotesListener;
|
|
|
24 |
use League\CommonMark\Extension\Footnote\Node\Footnote;
|
|
|
25 |
use League\CommonMark\Extension\Footnote\Node\FootnoteBackref;
|
|
|
26 |
use League\CommonMark\Extension\Footnote\Node\FootnoteContainer;
|
|
|
27 |
use League\CommonMark\Extension\Footnote\Node\FootnoteRef;
|
|
|
28 |
use League\CommonMark\Extension\Footnote\Parser\AnonymousFootnoteRefParser;
|
|
|
29 |
use League\CommonMark\Extension\Footnote\Parser\FootnoteRefParser;
|
|
|
30 |
use League\CommonMark\Extension\Footnote\Parser\FootnoteStartParser;
|
|
|
31 |
use League\CommonMark\Extension\Footnote\Renderer\FootnoteBackrefRenderer;
|
|
|
32 |
use League\CommonMark\Extension\Footnote\Renderer\FootnoteContainerRenderer;
|
|
|
33 |
use League\CommonMark\Extension\Footnote\Renderer\FootnoteRefRenderer;
|
|
|
34 |
use League\CommonMark\Extension\Footnote\Renderer\FootnoteRenderer;
|
|
|
35 |
use League\Config\ConfigurationBuilderInterface;
|
|
|
36 |
use Nette\Schema\Expect;
|
|
|
37 |
|
|
|
38 |
final class FootnoteExtension implements ConfigurableExtensionInterface
|
|
|
39 |
{
|
|
|
40 |
public function configureSchema(ConfigurationBuilderInterface $builder): void
|
|
|
41 |
{
|
|
|
42 |
$builder->addSchema('footnote', Expect::structure([
|
|
|
43 |
'backref_class' => Expect::string('footnote-backref'),
|
|
|
44 |
'backref_symbol' => Expect::string('↩'),
|
|
|
45 |
'container_add_hr' => Expect::bool(true),
|
|
|
46 |
'container_class' => Expect::string('footnotes'),
|
|
|
47 |
'ref_class' => Expect::string('footnote-ref'),
|
|
|
48 |
'ref_id_prefix' => Expect::string('fnref:'),
|
|
|
49 |
'footnote_class' => Expect::string('footnote'),
|
|
|
50 |
'footnote_id_prefix' => Expect::string('fn:'),
|
|
|
51 |
]));
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
public function register(EnvironmentBuilderInterface $environment): void
|
|
|
55 |
{
|
|
|
56 |
$environment->addBlockStartParser(new FootnoteStartParser(), 51);
|
|
|
57 |
$environment->addInlineParser(new AnonymousFootnoteRefParser(), 35);
|
|
|
58 |
$environment->addInlineParser(new FootnoteRefParser(), 51);
|
|
|
59 |
|
|
|
60 |
$environment->addRenderer(FootnoteContainer::class, new FootnoteContainerRenderer());
|
|
|
61 |
$environment->addRenderer(Footnote::class, new FootnoteRenderer());
|
|
|
62 |
$environment->addRenderer(FootnoteRef::class, new FootnoteRefRenderer());
|
|
|
63 |
$environment->addRenderer(FootnoteBackref::class, new FootnoteBackrefRenderer());
|
|
|
64 |
|
|
|
65 |
$environment->addEventListener(DocumentParsedEvent::class, [new AnonymousFootnotesListener(), 'onDocumentParsed'], 40);
|
|
|
66 |
$environment->addEventListener(DocumentParsedEvent::class, [new FixOrphanedFootnotesAndRefsListener(), 'onDocumentParsed'], 30);
|
|
|
67 |
$environment->addEventListener(DocumentParsedEvent::class, [new NumberFootnotesListener(), 'onDocumentParsed'], 20);
|
|
|
68 |
$environment->addEventListener(DocumentParsedEvent::class, [new GatherFootnotesListener(), 'onDocumentParsed'], 10);
|
|
|
69 |
}
|
|
|
70 |
}
|