xref: /webtrees/app/CommonMark/XrefExtension.php (revision e93a8df2f8d797005750082cc3766c0e80799688)
10a016d04SGreg Roach<?php
23976b470SGreg Roach
30a016d04SGreg Roach/**
40a016d04SGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
60a016d04SGreg Roach * This program is free software: you can redistribute it and/or modify
70a016d04SGreg Roach * it under the terms of the GNU General Public License as published by
80a016d04SGreg Roach * the Free Software Foundation, either version 3 of the License, or
90a016d04SGreg Roach * (at your option) any later version.
100a016d04SGreg Roach * This program is distributed in the hope that it will be useful,
110a016d04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
120a016d04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
130a016d04SGreg Roach * GNU General Public License for more details.
140a016d04SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
160a016d04SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
200a016d04SGreg Roachnamespace Fisharebest\Webtrees\CommonMark;
210a016d04SGreg Roach
220a016d04SGreg Roachuse Fisharebest\Webtrees\Tree;
236f595250SGreg Roachuse League\CommonMark\Environment\EnvironmentBuilderInterface;
244a1f1d43SGreg Roachuse League\CommonMark\Extension\ExtensionInterface;
250a016d04SGreg Roach
260a016d04SGreg Roach/**
270a016d04SGreg Roach * Convert XREFs within markdown text to links
280a016d04SGreg Roach */
294a1f1d43SGreg Roachclass XrefExtension implements ExtensionInterface
30c1010edaSGreg Roach{
31c4943cffSGreg Roach    private Tree $tree;
320a016d04SGreg Roach
330a016d04SGreg Roach    /**
34c4943cffSGreg Roach     * @param Tree $tree Match XREFs in this tree
350a016d04SGreg Roach     */
36c1010edaSGreg Roach    public function __construct(Tree $tree)
37c1010edaSGreg Roach    {
380a016d04SGreg Roach        $this->tree = $tree;
390a016d04SGreg Roach    }
400a016d04SGreg Roach
416f595250SGreg Roach    /**
426f595250SGreg Roach     * @param EnvironmentBuilderInterface $environment
436f595250SGreg Roach     */
446f595250SGreg Roach    public function register(EnvironmentBuilderInterface $environment): void
45c1010edaSGreg Roach    {
464a1f1d43SGreg Roach        $environment
47eec99f1aSGreg Roach            ->addInlineParser(new XrefParser($this->tree))
48def9659eSGreg Roach            ->addRenderer(XrefNode::class, new XrefRenderer());
490a016d04SGreg Roach    }
500a016d04SGreg Roach}
51