| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
/*
|
|
|
6 |
* This is part of the league/commonmark package.
|
|
|
7 |
*
|
|
|
8 |
* (c) Martin Hasoň <martin.hason@gmail.com>
|
|
|
9 |
* (c) Webuni s.r.o. <info@webuni.cz>
|
|
|
10 |
* (c) Colin O'Dell <colinodell@gmail.com>
|
|
|
11 |
*
|
|
|
12 |
* For the full copyright and license information, please view the LICENSE
|
|
|
13 |
* file that was distributed with this source code.
|
|
|
14 |
*/
|
|
|
15 |
|
|
|
16 |
namespace League\CommonMark\Extension\Table;
|
|
|
17 |
|
|
|
18 |
use League\CommonMark\Environment\EnvironmentBuilderInterface;
|
|
|
19 |
use League\CommonMark\Extension\ConfigurableExtensionInterface;
|
|
|
20 |
use League\CommonMark\Renderer\HtmlDecorator;
|
|
|
21 |
use League\Config\ConfigurationBuilderInterface;
|
|
|
22 |
use Nette\Schema\Expect;
|
|
|
23 |
|
|
|
24 |
final class TableExtension implements ConfigurableExtensionInterface
|
|
|
25 |
{
|
|
|
26 |
public function configureSchema(ConfigurationBuilderInterface $builder): void
|
|
|
27 |
{
|
|
|
28 |
$builder->addSchema('table', Expect::structure([
|
|
|
29 |
'wrap' => Expect::structure([
|
|
|
30 |
'enabled' => Expect::bool()->default(false),
|
|
|
31 |
'tag' => Expect::string()->default('div'),
|
|
|
32 |
'attributes' => Expect::arrayOf(Expect::string()),
|
|
|
33 |
]),
|
|
|
34 |
]));
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
public function register(EnvironmentBuilderInterface $environment): void
|
|
|
38 |
{
|
|
|
39 |
$tableRenderer = new TableRenderer();
|
|
|
40 |
if ($environment->getConfiguration()->get('table/wrap/enabled')) {
|
|
|
41 |
$tableRenderer = new HtmlDecorator($tableRenderer, $environment->getConfiguration()->get('table/wrap/tag'), $environment->getConfiguration()->get('table/wrap/attributes'));
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
$environment
|
|
|
45 |
->addBlockStartParser(new TableStartParser())
|
|
|
46 |
|
|
|
47 |
->addRenderer(Table::class, $tableRenderer)
|
|
|
48 |
->addRenderer(TableSection::class, new TableSectionRenderer())
|
|
|
49 |
->addRenderer(TableRow::class, new TableRowRenderer())
|
|
|
50 |
->addRenderer(TableCell::class, new TableCellRenderer());
|
|
|
51 |
}
|
|
|
52 |
}
|