Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use phpDocumentor\Guides\Compiler\NodeTransformer;
use phpDocumentor\Guides\Nodes\Inline\CrossReferenceNode;
use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;
use phpDocumentor\Guides\Nodes\InlineCompoundNode;
use phpDocumentor\Guides\Nodes\Node;
use phpDocumentor\Guides\Nodes\PrefixedLinkTargetNode;
use T3Docs\Typo3DocsTheme\Inventory\Typo3VersionService;
Expand Down Expand Up @@ -50,8 +51,8 @@ public function leaveNode(Node $node, CompilerContextInterface $compilerContext)
if ($node instanceof PrefixedLinkTargetNode) {
$prefix = $node->getPrefix();
}
assert(is_string($node->getValue()));
return new ReferenceNode('guide-' . $node->getTargetReference(), $node->getValue(), $node->getInterlinkDomain(), $node->getInterlinkGroup(), $prefix);
assert($node instanceof InlineCompoundNode);
return new ReferenceNode('guide-' . $node->getTargetReference(), $node->getChildren(), $node->getInterlinkDomain(), $node->getInterlinkGroup(), $prefix);
}
return $node;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function leaveNode(Node $node, CompilerContextInterface $compilerContext)
if ($node instanceof ReferenceNode) {
$newRef = new ReferenceNode(
$node->getTargetReference(),
$node->getValue(),
$node->getChildren(),
'',
$node->getLinkType(),
$node->getPrefix()
Expand All @@ -59,7 +59,7 @@ public function leaveNode(Node $node, CompilerContextInterface $compilerContext)
if ($node instanceof DocReferenceNode) {
$newDocRef = new DocReferenceNode(
$node->getTargetReference(),
$node->getValue(),
$node->getChildren(),
);
return $newDocRef;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ public function leaveNode(Node $node, CompilerContextInterface $compilerContext)
if (!str_starts_with($node->getTargetReference(), 'https://docs.typo3.org/permalink/')) {
return $node;
}
$value = $node->getValue();
if ($value === $node->getTargetReference()) {
$value = '';
}
// When the link's visible label equals its URL (auto-linkified plain URL),
// drop the children so the resolver fills in the canonical title.
$children = $node->toString() === $node->getTargetReference() ? [] : $node->getChildren();
$url = str_replace('https://docs.typo3.org/permalink/', '', ($node->getTargetReference()));
$version = null;
$interlink = null;
Expand All @@ -54,7 +53,7 @@ public function leaveNode(Node $node, CompilerContextInterface $compilerContext)
if ($version !== null && $interlink !== null) {
$interlink = $interlink . '/' . $version;
}
$node = new ReferenceNode($url, $value, $interlink ?? '');
$node = new ReferenceNode($url, $children, $interlink ?? '');
return $node;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
private string $interlinkDomain,
private string $linkType
) {
parent::__construct(self::TYPE, $fileLink, $fileLabel, [new PlainTextInlineNode($fileLabel)]);
parent::__construct(self::TYPE, $fileLink, [new PlainTextInlineNode($fileLabel)]);
}

public function getFileLink(): string
Expand Down
3 changes: 2 additions & 1 deletion packages/typo3-docs-theme/src/TextRoles/ApiClassTextRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand Down Expand Up @@ -54,6 +55,6 @@ protected function createNode(string $referenceTarget, string|null $referenceNam
$interlink = 'api';
}

return new ReferenceNode($reference, $referenceName ?? '', $interlink, self::TYPE, $prefix);
return new ReferenceNode($reference, $referenceName ? [new PlainTextInlineNode($referenceName)] : [], $interlink, self::TYPE, $prefix);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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\DocumentParserContext;
Expand Down Expand Up @@ -56,7 +57,7 @@ protected function createNode(DocumentParserContext $documentParserContext, stri
$id = $this->anchorReducer->reduceAnchor($referenceTarget);
}

return new ReferenceNode($id, $referenceName ?? '', $interlinkDomain, 'php:' . $this->getName());
return new ReferenceNode($id, $referenceName ? [new PlainTextInlineNode($referenceName)] : [], $interlinkDomain, 'php:' . $this->getName());
}

/** @return array{text:?string,uri:string} */
Expand Down
6 changes: 3 additions & 3 deletions packages/typo3-docs-theme/src/TextRoles/FileTextRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public function getAliases(): array

protected function createNode(DocumentParserContext $documentParserContext, string $referenceTarget, string|null $referenceName, string $role): AbstractLinkInlineNode
{
return $this->createNodeWithInterlink($documentParserContext, $referenceTarget, '', $referenceName);
return $this->createNodeWithInterlink($documentParserContext, $referenceTarget, '', $referenceName ?? $referenceTarget);
}

private function createNodeWithInterlink(DocumentParserContext $documentParserContext, string $referenceTarget, string $interlinkDomain, string|null $referenceName): AbstractLinkInlineNode
private function createNodeWithInterlink(DocumentParserContext $documentParserContext, string $referenceTarget, string $interlinkDomain, string $fileLabel): AbstractLinkInlineNode
{
return new FileInlineNode($referenceTarget, $referenceName ?? $referenceTarget, $interlinkDomain, 'typo3:file');
return new FileInlineNode($referenceTarget, $fileLabel, $interlinkDomain, 'typo3:file');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use phpDocumentor\Guides\Nodes\Inline\AbstractLinkInlineNode;
use phpDocumentor\Guides\Nodes\Inline\HyperLinkNode;
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
use phpDocumentor\Guides\RestructuredText\TextRoles\AbstractReferenceTextRole;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -37,8 +38,10 @@ protected function createNode(string $referenceTarget, string|null $referenceNam
{
if ((int)$referenceTarget <= 0) {
$this->logger->warning(sprintf('Expected a positive integer as issue number. Found %s', $referenceTarget));
return new HyperLinkNode($referenceName ?? 'Forge', self::FORGE_URL);
$label = $referenceName ?? 'Forge';
return new HyperLinkNode([new PlainTextInlineNode($label)], self::FORGE_URL);
}
return new HyperLinkNode($referenceName ?? sprintf(self::FORGE_DEFAULT_LABEL, $referenceTarget), sprintf(self::FORGE_ISSUE_URL, $referenceTarget));
$label = $referenceName ?? sprintf(self::FORGE_DEFAULT_LABEL, $referenceTarget);
return new HyperLinkNode([new PlainTextInlineNode($label)], sprintf(self::FORGE_ISSUE_URL, $referenceTarget));
}
}
3 changes: 2 additions & 1 deletion packages/typo3-docs-theme/src/TextRoles/T3extTextRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand Down Expand Up @@ -46,6 +47,6 @@ protected function createNode(
}
$terLink = sprintf('https://extensions.typo3.org/extension/%s', $extKey);
$extName = $referenceName ?? 'EXT:' . $extKey;
return new HyperLinkNode($extName, $terLink);
return new HyperLinkNode([new PlainTextInlineNode($extName)], $terLink);
}
}
3 changes: 2 additions & 1 deletion packages/typo3-docs-theme/src/TextRoles/T3srcTextRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand Down Expand Up @@ -55,6 +56,6 @@ protected function createNode(
}
$gitHubLink = sprintf('https://github.com/typo3/typo3/blob/%s/%s', $typo3Version, $fileLink);
$fileName = $referenceName ?? str_replace('typo3/sysext/', 'EXT:', $fileLink) . ' (GitHub)';
return new HyperLinkNode($fileName, $gitHubLink);
return new HyperLinkNode([new PlainTextInlineNode($fileName)], $gitHubLink);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace T3Docs\Typo3DocsTheme\TextRoles;

use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;
use phpDocumentor\Guides\ReferenceResolvers\AnchorNormalizer;
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
Expand All @@ -21,17 +23,19 @@ public function __construct(

protected function createNode(DocumentParserContext $documentParserContext, string $referenceTarget, string|null $referenceName, string $role): ReferenceNode
{
$children = $referenceName ? [new PlainTextInlineNode($referenceName)] : [];
if (preg_match(self::INTERLINK_NAME_REGEX, $referenceTarget, $matches)) {
return $this->createNodeWithInterlink($documentParserContext, $matches[2], $matches[1], $referenceName);
return $this->createNodeWithInterlink($documentParserContext, $matches[2], $matches[1], $children);
}
return $this->createNodeWithInterlink($documentParserContext, $referenceTarget, '', $referenceName);
return $this->createNodeWithInterlink($documentParserContext, $referenceTarget, '', $children);
}

private function createNodeWithInterlink(DocumentParserContext $documentParserContext, string $referenceTarget, string $interlinkDomain, string|null $referenceName): ReferenceNode
/** @param list<InlineNodeInterface> $children */
private function createNodeWithInterlink(DocumentParserContext $documentParserContext, string $referenceTarget, string $interlinkDomain, array $children): ReferenceNode
{
$id = $this->anchorNormalizer->reduceAnchor($referenceTarget);

return new ReferenceNode($id, $referenceName ?? '', $interlinkDomain, 'typo3:' . $this->getName());
return new ReferenceNode($id, $children, $interlinkDomain, 'typo3:' . $this->getName());
}

public function getName(): string
Expand Down
12 changes: 8 additions & 4 deletions packages/typo3-docs-theme/src/TextRoles/ViewhelperTextRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace T3Docs\Typo3DocsTheme\TextRoles;

use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;
use phpDocumentor\Guides\ReferenceResolvers\AnchorNormalizer;
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
Expand All @@ -25,17 +27,19 @@ public function __construct(

protected function createNode(DocumentParserContext $documentParserContext, string $referenceTarget, string|null $referenceName, string $role): ReferenceNode
{
$children = $referenceName ? [new PlainTextInlineNode($referenceName)] : [];
if (preg_match(self::INTERLINK_NAME_REGEX, $referenceTarget, $matches)) {
return $this->createNodeWithInterlink($documentParserContext, $matches[2], $matches[1], $referenceName);
return $this->createNodeWithInterlink($documentParserContext, $matches[2], $matches[1], $children);
}
return $this->createNodeWithInterlink($documentParserContext, $referenceTarget, '', $referenceName);
return $this->createNodeWithInterlink($documentParserContext, $referenceTarget, '', $children);
}

private function createNodeWithInterlink(DocumentParserContext $documentParserContext, string $referenceTarget, string $interlinkDomain, string|null $referenceName): ReferenceNode
/** @param list<InlineNodeInterface> $children */
private function createNodeWithInterlink(DocumentParserContext $documentParserContext, string $referenceTarget, string $interlinkDomain, array $children): ReferenceNode
{
$id = $this->anchorNormalizer->reduceAnchor($referenceTarget);

return new ReferenceNode($id, $referenceName ?? '', $interlinkDomain, 'typo3:' . $this->getName());
return new ReferenceNode($id, $children, $interlinkDomain, 'typo3:' . $this->getName());
}

public function getName(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static function providerForInventoryKeysWithVersions(): \Generator
public function versionInventoryCreatesVersionedUrl(string $inventoryKey, string $expected): void
{
$messages = new Messages();
$node = new ReferenceNode('someReference', '', $inventoryKey);
$node = new ReferenceNode('someReference', [], $inventoryKey);
self::assertEquals($expected, $this->subject->previewUrl($inventoryKey));
self::assertCount(0, $messages->getWarnings());
}
Expand Down
Loading