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
13declare(strict_types=1);
14
15namespace League\CommonMark\Extension\Footnote;
16
17use League\CommonMark\ConfigurableEnvironmentInterface;
18use League\CommonMark\Event\DocumentParsedEvent;
19use League\CommonMark\Extension\ExtensionInterface;
20use League\CommonMark\Extension\Footnote\Event\AnonymousFootnotesListener;
21use League\CommonMark\Extension\Footnote\Event\GatherFootnotesListener;
22use League\CommonMark\Extension\Footnote\Event\NumberFootnotesListener;
23use League\CommonMark\Extension\Footnote\Node\Footnote;
24use League\CommonMark\Extension\Footnote\Node\FootnoteBackref;
25use League\CommonMark\Extension\Footnote\Node\FootnoteContainer;
26use League\CommonMark\Extension\Footnote\Node\FootnoteRef;
27use League\CommonMark\Extension\Footnote\Parser\AnonymousFootnoteRefParser;
28use League\CommonMark\Extension\Footnote\Parser\FootnoteParser;
29use League\CommonMark\Extension\Footnote\Parser\FootnoteRefParser;
30use League\CommonMark\Extension\Footnote\Renderer\FootnoteBackrefRenderer;
31use League\CommonMark\Extension\Footnote\Renderer\FootnoteContainerRenderer;
32use League\CommonMark\Extension\Footnote\Renderer\FootnoteRefRenderer;
33use League\CommonMark\Extension\Footnote\Renderer\FootnoteRenderer;
34
35final class FootnoteExtension implements ExtensionInterface
36{
37    public function register(ConfigurableEnvironmentInterface $environment)
38    {
39        $environment->addBlockParser(new FootnoteParser(), 51);
40        $environment->addInlineParser(new AnonymousFootnoteRefParser(), 35);
41        $environment->addInlineParser(new FootnoteRefParser(), 51);
42
43        $environment->addBlockRenderer(FootnoteContainer::class, new FootnoteContainerRenderer());
44        $environment->addBlockRenderer(Footnote::class, new FootnoteRenderer());
45
46        $environment->addInlineRenderer(FootnoteRef::class, new FootnoteRefRenderer());
47        $environment->addInlineRenderer(FootnoteBackref::class, new FootnoteBackrefRenderer());
48
49        $environment->addEventListener(DocumentParsedEvent::class, [new AnonymousFootnotesListener(), 'onDocumentParsed']);
50        $environment->addEventListener(DocumentParsedEvent::class, [new NumberFootnotesListener(), 'onDocumentParsed']);
51        $environment->addEventListener(DocumentParsedEvent::class, [new GatherFootnotesListener(), 'onDocumentParsed']);
52    }
53}
54