xref: /webtrees/app/CommonMark/CensusTableExtension.php (revision 873953697c930fadbf3243d2b8c0029fd684da0e)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2018 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 */
16namespace Fisharebest\Webtrees\CommonMark;
17
18use League\CommonMark\Block\Parser\BlockParserInterface;
19use League\CommonMark\Block\Renderer\BlockRendererInterface;
20use League\CommonMark\Extension\Extension;
21use Webuni\CommonMark\TableExtension\Table;
22use Webuni\CommonMark\TableExtension\TableCell;
23use Webuni\CommonMark\TableExtension\TableCellRenderer;
24use Webuni\CommonMark\TableExtension\TableRenderer;
25use Webuni\CommonMark\TableExtension\TableRow;
26use Webuni\CommonMark\TableExtension\TableRowRenderer;
27use Webuni\CommonMark\TableExtension\TableRows;
28use Webuni\CommonMark\TableExtension\TableRowsRenderer;
29
30/**
31 * Convert webtrees 1.x census-assistant markup into tables.
32 * Note that webtrees 2.0 generates markdown tables directly.
33 *
34 * Based on the table parser from webuni/commonmark-table-extension.
35 */
36class CensusTableExtension extends Extension
37{
38    /**
39     * Returns a list of block parsers to add to the existing list
40     *
41     * @return BlockParserInterface[]
42     */
43    public function getBlockParsers(): array
44    {
45        return [
46            new CensusTableParser(),
47        ];
48    }
49
50    /**
51     * Returns a list of block renderers to add to the existing list
52     *
53     * The list keys are the block class names which the corresponding value (renderer) will handle.
54     *
55     * @return BlockRendererInterface[]
56     */
57    public function getBlockRenderers(): array
58    {
59        return [
60            Table::class     => new TableRenderer(),
61            TableRows::class => new TableRowsRenderer(),
62            TableRow::class  => new TableRowRenderer(),
63            TableCell::class => new TableCellRenderer(),
64        ];
65    }
66
67    /**
68     * @return string
69     */
70    public function getName(): string
71    {
72        return 'censustabletable';
73    }
74}
75