xref: /webtrees/app/CommonMark/CensusTableExtension.php (revision ecf66805cdf435857ce4ed0eb577cfd1296f8989)
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	 * Returns a list of block parsers to add to the existing list
39	 *
40	 * @return BlockParserInterface[]
41	 */
42	public function getBlockParsers() {
43		return [
44			new CensusTableParser,
45		];
46	}
47
48	/**
49	 * Returns a list of block renderers to add to the existing list
50	 *
51	 * The list keys are the block class names which the corresponding value (renderer) will handle.
52	 *
53	 * @return BlockRendererInterface[]
54	 */
55	public function getBlockRenderers() {
56		return [
57			Table::class     => new TableRenderer,
58			TableRows::class => new TableRowsRenderer,
59			TableRow::class  => new TableRowRenderer,
60			TableCell::class => new TableCellRenderer,
61		];
62	}
63
64	/**
65	 * @return string
66	 */
67	public function getName() {
68		return 'censustabletable';
69	}
70}
71