Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
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),
32
            'insert' => Expect::anyOf(HeadingPermalinkProcessor::INSERT_BEFORE, HeadingPermalinkProcessor::INSERT_AFTER)->default(HeadingPermalinkProcessor::INSERT_BEFORE),
33
            'id_prefix' => Expect::string()->default('content'),
34
            'fragment_prefix' => Expect::string()->default('content'),
35
            'html_class' => Expect::string()->default('heading-permalink'),
36
            'title' => Expect::string()->default('Permalink'),
37
            'symbol' => Expect::string()->default(HeadingPermalinkRenderer::DEFAULT_SYMBOL),
38
            'aria_hidden' => Expect::bool()->default(true),
39
        ]));
40
    }
41
 
42
    public function register(EnvironmentBuilderInterface $environment): void
43
    {
44
        $environment->addEventListener(DocumentParsedEvent::class, new HeadingPermalinkProcessor(), -100);
45
        $environment->addRenderer(HeadingPermalink::class, new HeadingPermalinkRenderer());
46
    }
47
}