10a016d04SGreg Roach<?php 23976b470SGreg Roach 30a016d04SGreg Roach/** 40a016d04SGreg Roach * webtrees: online genealogy 589f7189bSGreg Roach * Copyright (C) 2021 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; 23*6f595250SGreg 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 /** 340a016d04SGreg Roach * MarkdownXrefParser constructor. 350a016d04SGreg Roach * 36c4943cffSGreg Roach * @param Tree $tree Match XREFs in this tree 370a016d04SGreg Roach */ 38c1010edaSGreg Roach public function __construct(Tree $tree) 39c1010edaSGreg Roach { 400a016d04SGreg Roach $this->tree = $tree; 410a016d04SGreg Roach } 420a016d04SGreg Roach 43*6f595250SGreg Roach /** 44*6f595250SGreg Roach * @param EnvironmentBuilderInterface $environment 45*6f595250SGreg Roach */ 46*6f595250SGreg Roach public function register(EnvironmentBuilderInterface $environment): void 47c1010edaSGreg Roach { 484a1f1d43SGreg Roach $environment 49eec99f1aSGreg Roach ->addInlineParser(new XrefParser($this->tree)) 50*6f595250SGreg Roach ->addRenderer(XrefNode::class, new XrefRenderer); 510a016d04SGreg Roach } 520a016d04SGreg Roach} 53