1<?php
2
3/*
4 * This file is part of the clockoon/dokuwiki-commonmark-plugin package.
5 *
6 * (c) Sungbin Jeon <clockoon@gmail.com>
7 *
8 * Original code based on the followings:
9 * - CommonMark JS reference parser (https://bitly.com/commonmark-js) (c) John MacFarlane
10 * - league/commonmark (https://github.com/thephpleague/commonmark) (c) Colin O'Dell <colinodell@gmail.com>
11 *
12 * For the full copyright and license information, please view the LICENSE
13 * file that was distributed with this source code.
14 */
15
16declare(strict_types=1);
17
18namespace DokuWiki\Plugin\Commonmark\Extension;
19
20use League\CommonMark\ConfigurableEnvironmentInterface;
21use League\CommonMark\Event\DocumentParsedEvent;
22use League\CommonMark\Extension\ExtensionInterface;
23use League\CommonMark\Extension\Footnote\Event\AnonymousFootnotesListener;
24use League\CommonMark\Extension\Footnote\Event\GatherFootnotesListener;
25use League\CommonMark\Extension\Footnote\Event\NumberFootnotesListener;
26use League\CommonMark\Extension\Footnote\Node\Footnote;
27use League\CommonMark\Extension\Footnote\Node\FootnoteBackref;
28use League\CommonMark\Extension\Footnote\Node\FootnoteContainer;
29use League\CommonMark\Extension\Footnote\Node\FootnoteRef;
30use League\CommonMark\Extension\Footnote\Parser\AnonymousFootnoteRefParser;
31use League\CommonMark\Extension\Footnote\Parser\FootnoteParser;
32use League\CommonMark\Extension\Footnote\Parser\FootnoteRefParser;
33use Dokuwiki\Plugin\Commonmark\Extension\Renderer\Inline\FootnoteBackrefRenderer;
34use Dokuwiki\Plugin\Commonmark\Extension\Renderer\Block\FootnoteContainerRenderer;
35use Dokuwiki\Plugin\Commonmark\Extension\Renderer\Inline\FootnoteRefRenderer;
36use Dokuwiki\Plugin\Commonmark\Extension\Renderer\Block\FootnoteRenderer;
37
38final class FootnotetoDokuwikiExtension implements ExtensionInterface
39{
40    public function register(ConfigurableEnvironmentInterface $environment)
41    {
42        $environment->addBlockParser(new FootnoteParser(), 51);
43        $environment->addInlineParser(new AnonymousFootnoteRefParser(), 35);
44        $environment->addInlineParser(new FootnoteRefParser(), 51);
45
46        $environment->addBlockRenderer(FootnoteContainer::class, new FootnoteContainerRenderer());
47        $environment->addBlockRenderer(Footnote::class, new FootnoteRenderer());
48        $environment->addInlineRenderer(FootnoteBackref::class, new FootnoteBackrefRenderer());
49        $environment->addInlineRenderer(FootnoteRef::class, new FootnoteRefRenderer());
50
51        $environment->addEventListener(DocumentParsedEvent::class, [new AnonymousFootnotesListener(), 'onDocumentParsed']);
52        $environment->addEventListener(DocumentParsedEvent::class, [new NumberFootnotesListener(), 'onDocumentParsed']);
53        $environment->addEventListener(DocumentParsedEvent::class, [new GatherFootnotesListener(), 'onDocumentParsed']);
54    }
55}
56