-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeBlockTitleExtension.php
More file actions
42 lines (34 loc) · 1.17 KB
/
Copy pathCodeBlockTitleExtension.php
File metadata and controls
42 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
declare(strict_types=1);
/*
* This file is part of the ALTO Commonmark package.
*
* © 2025-Present Simon André
*
* For full copyright and license information, please see
* the LICENSE file distributed with this source code.
*/
namespace Alto\CommonMark\Extension\CodeBlockTitle;
use League\CommonMark\Environment\EnvironmentBuilderInterface;
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode;
use League\CommonMark\Extension\CommonMark\Renderer\Block\FencedCodeRenderer;
use League\CommonMark\Extension\ExtensionInterface;
use League\CommonMark\Renderer\NodeRendererInterface;
final readonly class CodeBlockTitleExtension implements ExtensionInterface
{
public function __construct(
private ?NodeRendererInterface $baseRenderer = null,
) {
}
public function register(EnvironmentBuilderInterface $environment): void
{
$base = $this->baseRenderer ?? new FencedCodeRenderer();
$environment->addRenderer(
FencedCode::class,
new CodeBlockTitleRenderer($base),
// higher priority than default so we run first
10
// TODO if/check herer: 'return'
);
}
}