xref: /webtrees/app/CommonMark/CensusTableExtension.php (revision 8121b9bec19818120092699199161a1357bb8f3f)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\CommonMark;
19
20use League\CommonMark\Block\Parser\BlockParserInterface;
21use League\CommonMark\Block\Renderer\BlockRendererInterface;
22use League\CommonMark\Extension\Extension;
23use Webuni\CommonMark\TableExtension\Table;
24use Webuni\CommonMark\TableExtension\TableCell;
25use Webuni\CommonMark\TableExtension\TableCellRenderer;
26use Webuni\CommonMark\TableExtension\TableRenderer;
27use Webuni\CommonMark\TableExtension\TableRow;
28use Webuni\CommonMark\TableExtension\TableRowRenderer;
29use Webuni\CommonMark\TableExtension\TableRows;
30use Webuni\CommonMark\TableExtension\TableRowsRenderer;
31
32/**
33 * Convert webtrees 1.x census-assistant markup into tables.
34 * Note that webtrees 2.0 generates markdown tables directly.
35 *
36 * Based on the table parser from webuni/commonmark-table-extension.
37 */
38class CensusTableExtension extends Extension
39{
40    /**
41     * Returns a list of block parsers to add to the existing list
42     *
43     * @return BlockParserInterface[]
44     */
45    public function getBlockParsers(): array
46    {
47        return [
48            new CensusTableParser(),
49        ];
50    }
51
52    /**
53     * Returns a list of block renderers to add to the existing list
54     *
55     * The list keys are the block class names which the corresponding value (renderer) will handle.
56     *
57     * @return BlockRendererInterface[]
58     */
59    public function getBlockRenderers(): array
60    {
61        return [
62            Table::class     => new TableRenderer(),
63            TableRows::class => new TableRowsRenderer(),
64            TableRow::class  => new TableRowRenderer(),
65            TableCell::class => new TableCellRenderer(),
66        ];
67    }
68
69    /**
70     * @return string
71     */
72    public function getName(): string
73    {
74        return 'censustabletable';
75    }
76}
77