| 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\HeadingPermalink;
|
|
|
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 |
/**
|
|
|
23 |
* Extension which automatically anchor links to heading elements
|
|
|
24 |
*/
|
|
|
25 |
final class HeadingPermalinkExtension implements ConfigurableExtensionInterface
|
|
|
26 |
{
|
|
|
27 |
public function configureSchema(ConfigurationBuilderInterface $builder): void
|
|
|
28 |
{
|
|
|
29 |
$builder->addSchema('heading_permalink', Expect::structure([
|
|
|
30 |
'min_heading_level' => Expect::int()->min(1)->max(6)->default(1),
|
|
|
31 |
'max_heading_level' => Expect::int()->min(1)->max(6)->default(6),
|
| 991 |
lars |
32 |
'insert' => Expect::anyOf(HeadingPermalinkProcessor::INSERT_BEFORE, HeadingPermalinkProcessor::INSERT_AFTER, HeadingPermalinkProcessor::INSERT_NONE)->default(HeadingPermalinkProcessor::INSERT_BEFORE),
|
| 148 |
lars |
33 |
'id_prefix' => Expect::string()->default('content'),
|
| 991 |
lars |
34 |
'apply_id_to_heading' => Expect::bool()->default(false),
|
|
|
35 |
'heading_class' => Expect::string()->default(''),
|
| 148 |
lars |
36 |
'fragment_prefix' => Expect::string()->default('content'),
|
|
|
37 |
'html_class' => Expect::string()->default('heading-permalink'),
|
|
|
38 |
'title' => Expect::string()->default('Permalink'),
|
|
|
39 |
'symbol' => Expect::string()->default(HeadingPermalinkRenderer::DEFAULT_SYMBOL),
|
|
|
40 |
'aria_hidden' => Expect::bool()->default(true),
|
|
|
41 |
]));
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
public function register(EnvironmentBuilderInterface $environment): void
|
|
|
45 |
{
|
|
|
46 |
$environment->addEventListener(DocumentParsedEvent::class, new HeadingPermalinkProcessor(), -100);
|
|
|
47 |
$environment->addRenderer(HeadingPermalink::class, new HeadingPermalinkRenderer());
|
|
|
48 |
}
|
|
|
49 |
}
|