|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This is part of the league/commonmark package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Martin Hasoň <[email protected]> |
|
9
|
|
|
* (c) Webuni s.r.o. <[email protected]> |
|
10
|
|
|
* (c) Colin O'Dell <[email protected]> |
|
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
|
128 |
|
public function configureSchema(ConfigurationBuilderInterface $builder): void |
|
27
|
|
|
{ |
|
28
|
128 |
|
$builder->addSchema('table', Expect::structure([ |
|
29
|
128 |
|
'wrap' => Expect::structure([ |
|
30
|
128 |
|
'enabled' => Expect::bool()->default(false), |
|
31
|
128 |
|
'tag' => Expect::string()->default('div'), |
|
32
|
128 |
|
'attributes' => Expect::arrayOf(Expect::string()), |
|
33
|
|
|
]), |
|
34
|
|
|
])); |
|
35
|
128 |
|
} |
|
36
|
|
|
|
|
37
|
128 |
|
public function register(EnvironmentBuilderInterface $environment): void |
|
38
|
|
|
{ |
|
39
|
128 |
|
$tableRenderer = new TableRenderer(); |
|
40
|
128 |
|
if ($environment->getConfiguration()->get('table/wrap/enabled')) { |
|
41
|
2 |
|
$tableRenderer = new HtmlDecorator($tableRenderer, $environment->getConfiguration()->get('table/wrap/tag'), $environment->getConfiguration()->get('table/wrap/attributes')); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$environment |
|
45
|
128 |
|
->addBlockStartParser(new TableStartParser()) |
|
46
|
|
|
|
|
47
|
128 |
|
->addRenderer(Table::class, $tableRenderer) |
|
48
|
128 |
|
->addRenderer(TableSection::class, new TableSectionRenderer()) |
|
49
|
128 |
|
->addRenderer(TableRow::class, new TableRowRenderer()) |
|
50
|
128 |
|
->addRenderer(TableCell::class, new TableCellRenderer()); |
|
51
|
128 |
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|