| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
/*
|
|
|
6 |
* This file is part of the league/commonmark package.
|
|
|
7 |
*
|
|
|
8 |
* (c) Colin O'Dell <colinodell@gmail.com>
|
|
|
9 |
*
|
|
|
10 |
* For the full copyright and license information, please view the LICENSE
|
|
|
11 |
* file that was distributed with this source code.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
namespace League\CommonMark\Extension\DefaultAttributes;
|
|
|
15 |
|
|
|
16 |
use League\CommonMark\Environment\EnvironmentBuilderInterface;
|
|
|
17 |
use League\CommonMark\Event\DocumentParsedEvent;
|
|
|
18 |
use League\CommonMark\Extension\ConfigurableExtensionInterface;
|
|
|
19 |
use League\Config\ConfigurationBuilderInterface;
|
|
|
20 |
use Nette\Schema\Expect;
|
|
|
21 |
|
|
|
22 |
final class DefaultAttributesExtension implements ConfigurableExtensionInterface
|
|
|
23 |
{
|
|
|
24 |
public function configureSchema(ConfigurationBuilderInterface $builder): void
|
|
|
25 |
{
|
|
|
26 |
$builder->addSchema('default_attributes', Expect::arrayOf(
|
|
|
27 |
Expect::arrayOf(
|
|
|
28 |
Expect::type('string|string[]|bool|callable'), // attribute value(s)
|
|
|
29 |
'string' // attribute name
|
|
|
30 |
),
|
|
|
31 |
'string' // node FQCN
|
|
|
32 |
)->default([]));
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
public function register(EnvironmentBuilderInterface $environment): void
|
|
|
36 |
{
|
|
|
37 |
$environment->addEventListener(DocumentParsedEvent::class, [new ApplyDefaultAttributesProcessor(), 'onDocumentParsed']);
|
|
|
38 |
}
|
|
|
39 |
}
|