xref: /webtrees/app/CommonMark/XrefExtension.php (revision 0a016d046f63b3b1ece7ec913216782c17f0cbad)
1*0a016d04SGreg Roach<?php
2*0a016d04SGreg Roach/**
3*0a016d04SGreg Roach * webtrees: online genealogy
4*0a016d04SGreg Roach * Copyright (C) 2017 webtrees development team
5*0a016d04SGreg Roach * This program is free software: you can redistribute it and/or modify
6*0a016d04SGreg Roach * it under the terms of the GNU General Public License as published by
7*0a016d04SGreg Roach * the Free Software Foundation, either version 3 of the License, or
8*0a016d04SGreg Roach * (at your option) any later version.
9*0a016d04SGreg Roach * This program is distributed in the hope that it will be useful,
10*0a016d04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*0a016d04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12*0a016d04SGreg Roach * GNU General Public License for more details.
13*0a016d04SGreg Roach * You should have received a copy of the GNU General Public License
14*0a016d04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
15*0a016d04SGreg Roach */
16*0a016d04SGreg Roachnamespace Fisharebest\Webtrees\CommonMark;
17*0a016d04SGreg Roach
18*0a016d04SGreg Roachuse Fisharebest\Webtrees\Tree;
19*0a016d04SGreg Roachuse League\CommonMark\Extension\Extension;
20*0a016d04SGreg Roach
21*0a016d04SGreg Roach/**
22*0a016d04SGreg Roach * Convert XREFs within markdown text to links
23*0a016d04SGreg Roach */
24*0a016d04SGreg Roachclass XrefExtension extends Extension {
25*0a016d04SGreg Roach	/** @var Tree - match XREFs in this tree */
26*0a016d04SGreg Roach	private $tree;
27*0a016d04SGreg Roach
28*0a016d04SGreg Roach	/**
29*0a016d04SGreg Roach	 * MarkdownXrefParser constructor.
30*0a016d04SGreg Roach	 *
31*0a016d04SGreg Roach	 * @param Tree $tree
32*0a016d04SGreg Roach	 */
33*0a016d04SGreg Roach	public function __construct(Tree $tree) {
34*0a016d04SGreg Roach		$this->tree = $tree;
35*0a016d04SGreg Roach	}
36*0a016d04SGreg Roach
37*0a016d04SGreg Roach	/**
38*0a016d04SGreg Roach	 * @return array
39*0a016d04SGreg Roach	 */
40*0a016d04SGreg Roach	public function getInlineParsers() {
41*0a016d04SGreg Roach		return [
42*0a016d04SGreg Roach			new XrefParser($this->tree),
43*0a016d04SGreg Roach		];
44*0a016d04SGreg Roach	}
45*0a016d04SGreg Roach
46*0a016d04SGreg Roach	/**
47*0a016d04SGreg Roach	 * @return string
48*0a016d04SGreg Roach	 */
49*0a016d04SGreg Roach	public function getName() {
50*0a016d04SGreg Roach		return 'xref';
51*0a016d04SGreg Roach	}
52*0a016d04SGreg Roach}
53