forked from TYPO3-Documentation/render-guides
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiClassTextRole.php
More file actions
60 lines (50 loc) · 1.97 KB
/
ApiClassTextRole.php
File metadata and controls
60 lines (50 loc) · 1.97 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link https://phpdoc.org
*/
namespace T3Docs\Typo3DocsTheme\TextRoles;
use phpDocumentor\Guides\Nodes\Inline\AbstractLinkInlineNode;
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;
use phpDocumentor\Guides\ReferenceResolvers\AnchorNormalizer;
use phpDocumentor\Guides\RestructuredText\Parser\Interlink\InterlinkParser;
use phpDocumentor\Guides\RestructuredText\TextRoles\AbstractReferenceTextRole;
use phpDocumentor\Guides\RestructuredText\TextRoles\GenericLinkProvider;
final class ApiClassTextRole extends AbstractReferenceTextRole
{
final public const NAME = 'api-class';
final public const TYPE = 'api-class';
protected bool $useRawContent = true;
public function __construct(
private readonly GenericLinkProvider $genericLinkProvider,
private readonly AnchorNormalizer $anchorReducer,
private readonly InterlinkParser $interlinkParser,
) {}
public function getName(): string
{
return self::NAME;
}
/** @inheritDoc */
public function getAliases(): array
{
return [];
}
/** @return ReferenceNode */
protected function createNode(string $referenceTarget, string|null $referenceName, string $role): AbstractLinkInlineNode
{
$interlinkData = $this->interlinkParser->extractInterlink($referenceTarget);
$reference = $this->anchorReducer->reduceAnchor($interlinkData->reference);
$prefix = $this->genericLinkProvider->getLinkPrefix($role);
$interlink = $interlinkData->interlink;
if ($interlink === '') {
$interlink = 'api';
}
return new ReferenceNode($reference, $referenceName ? [new PlainTextInlineNode($referenceName)] : [], $interlink, self::TYPE, $prefix);
}
}