1eec99f1aSGreg Roach<?php 2eec99f1aSGreg Roach 3eec99f1aSGreg Roach/** 4eec99f1aSGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 6eec99f1aSGreg Roach * This program is free software: you can redistribute it and/or modify 7eec99f1aSGreg Roach * it under the terms of the GNU General Public License as published by 8eec99f1aSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9eec99f1aSGreg Roach * (at your option) any later version. 10eec99f1aSGreg Roach * This program is distributed in the hope that it will be useful, 11eec99f1aSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12eec99f1aSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13eec99f1aSGreg Roach * GNU General Public License for more details. 14eec99f1aSGreg 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/>. 16eec99f1aSGreg Roach */ 17eec99f1aSGreg Roach 18eec99f1aSGreg Roachdeclare(strict_types=1); 19eec99f1aSGreg Roach 20eec99f1aSGreg Roachnamespace Fisharebest\Webtrees\CommonMark; 21eec99f1aSGreg Roach 226f595250SGreg Roachuse League\CommonMark\Node\Node; 236f595250SGreg Roachuse League\CommonMark\Renderer\ChildNodeRendererInterface; 246f595250SGreg Roachuse League\CommonMark\Renderer\NodeRendererInterface; 256f595250SGreg Roachuse League\CommonMark\Util\HtmlElement; 266f595250SGreg Roachuse Stringable; 27eec99f1aSGreg Roach 28eec99f1aSGreg Roach/** 29eec99f1aSGreg Roach * Convert XREFs within markdown text to links 30eec99f1aSGreg Roach */ 316f595250SGreg Roachclass XrefRenderer implements NodeRendererInterface 32eec99f1aSGreg Roach{ 33eec99f1aSGreg Roach /** 346f595250SGreg Roach * @param Node $node 356f595250SGreg Roach * @param ChildNodeRendererInterface $childRenderer 36eec99f1aSGreg Roach * 376f595250SGreg Roach * @return Stringable 38eec99f1aSGreg Roach */ 396f595250SGreg Roach public function render(Node $node, ChildNodeRendererInterface $childRenderer): Stringable 40eec99f1aSGreg Roach { 416f595250SGreg Roach XrefNode::assertInstanceOf($node); 42eec99f1aSGreg Roach 436f595250SGreg Roach /** @var XrefNode $node */ 446f595250SGreg Roach $href = $node->record()->url(); 456f595250SGreg Roach $html = $node->record()->fullName(); 466f595250SGreg Roach 476f595250SGreg Roach return new HtmlElement('a', ['href' => $href], $html); 48eec99f1aSGreg Roach } 49eec99f1aSGreg Roach} 50