forked from TYPO3-Documentation/render-guides
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathT3extTextRole.php
More file actions
52 lines (44 loc) · 1.59 KB
/
T3extTextRole.php
File metadata and controls
52 lines (44 loc) · 1.59 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
<?php
namespace T3Docs\Typo3DocsTheme\TextRoles;
use phpDocumentor\Guides\Nodes\Inline\HyperLinkNode;
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
use phpDocumentor\Guides\RestructuredText\Parser\References\EmbeddedReferenceParser;
use phpDocumentor\Guides\RestructuredText\TextRoles\TextRole;
final class T3extTextRole implements TextRole
{
use EmbeddedReferenceParser;
final public const NAME = 't3ext';
public function getName(): string
{
return self::NAME;
}
/** @inheritDoc */
public function getAliases(): array
{
return [];
}
public function processNode(
DocumentParserContext $documentParserContext,
string $role,
string $content,
string $rawContent,
): HyperLinkNode {
$referenceData = $this->extractEmbeddedReference($content);
return $this->createNode($documentParserContext, $referenceData->reference, $referenceData->text, $role);
}
protected function createNode(
DocumentParserContext $documentParserContext,
string $referenceTarget,
string|null $referenceName,
string $role
): HyperLinkNode {
$extKey = $referenceTarget;
if (str_starts_with($extKey, 'EXT:')) {
$extKey = str_replace('EXT:', '', $extKey);
}
$terLink = sprintf('https://extensions.typo3.org/extension/%s', $extKey);
$extName = $referenceName ?? 'EXT:' . $extKey;
return new HyperLinkNode([new PlainTextInlineNode($extName)], $terLink);
}
}