Skip to content

Commit eb63f84

Browse files
committed
[FEATURE] Link to phpdomain API
1 parent f3fe39f commit eb63f84

File tree

10 files changed

+24533
-9
lines changed

10 files changed

+24533
-9
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ test-functional: ## Runs functional tests with phpunit/phpunit
4242
test-integration: ## Runs integration tests with phpunit/phpunit
4343
$(PHP_BIN) vendor/bin/phpunit --testsuite=integration
4444

45+
.PHONY: integration-baseline
46+
integration-baseline: ## Copies the output files of the integration tests into the expected directories, making a new baseline.
47+
$(PHP_BIN) tools/integration-test-copy-baseline.php
48+
4549
.PHONY: test-xml
4650
test-xml: ## Lint all guides.xml
4751
./tools/xmllint.sh

packages/guides-restructured-text/resources/config/guides-restructured-text.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
use phpDocumentor\Guides\RestructuredText\Parser\Productions\TitleRule;
107107
use phpDocumentor\Guides\RestructuredText\Parser\Productions\TransitionRule;
108108
use phpDocumentor\Guides\RestructuredText\TextRoles\AbbreviationTextRole;
109+
use phpDocumentor\Guides\RestructuredText\TextRoles\ApiClassTextRole;
109110
use phpDocumentor\Guides\RestructuredText\TextRoles\DefaultTextRoleFactory;
110111
use phpDocumentor\Guides\RestructuredText\TextRoles\DocReferenceTextRole;
111112
use phpDocumentor\Guides\RestructuredText\TextRoles\GenericLinkProvider;
@@ -168,6 +169,7 @@
168169
->set(GenericReferenceTextRole::class)
169170
->set(ReferenceTextRole::class)
170171
->set(AbbreviationTextRole::class)
172+
->set(ApiClassTextRole::class)
171173
->set(MathTextRole::class)
172174
->set(LiteralTextRole::class)
173175
->set(SpanTextRole::class)

packages/guides-restructured-text/src/RestructuredText/TextRoles/AbstractReferenceTextRole.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ abstract class AbstractReferenceTextRole implements TextRole
2222
{
2323
use EmbeddedReferenceParser;
2424

25+
protected bool $useRawContent = false;
26+
2527
public function processNode(
2628
DocumentParserContext $documentParserContext,
2729
string $role,
2830
string $content,
2931
string $rawContent,
3032
): AbstractLinkInlineNode {
31-
$referenceData = $this->extractEmbeddedReference($content);
33+
$referenceData = $this->extractEmbeddedReference($this->useRawContent ? $rawContent : $content);
3234

3335
return $this->createNode($referenceData->reference, $referenceData->text, $role);
3436
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link https://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Guides\RestructuredText\TextRoles;
15+
16+
use phpDocumentor\Guides\Nodes\Inline\AbstractLinkInlineNode;
17+
use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;
18+
use phpDocumentor\Guides\ReferenceResolvers\AnchorNormalizer;
19+
use phpDocumentor\Guides\RestructuredText\Parser\Interlink\InterlinkParser;
20+
21+
final class ApiClassTextRole extends AbstractReferenceTextRole
22+
{
23+
final public const NAME = 'api-class';
24+
final public const TYPE = 'api-class';
25+
protected bool $useRawContent = true;
26+
27+
public function __construct(
28+
private readonly GenericLinkProvider $genericLinkProvider,
29+
private readonly AnchorNormalizer $anchorReducer,
30+
private readonly InterlinkParser $interlinkParser,
31+
) {
32+
}
33+
34+
public function getName(): string
35+
{
36+
return self::NAME;
37+
}
38+
39+
/** @inheritDoc */
40+
public function getAliases(): array
41+
{
42+
return [];
43+
}
44+
45+
/** @return ReferenceNode */
46+
protected function createNode(string $referenceTarget, string|null $referenceName, string $role): AbstractLinkInlineNode
47+
{
48+
$interlinkData = $this->interlinkParser->extractInterlink($referenceTarget);
49+
$reference = $this->anchorReducer->reduceAnchor($interlinkData->reference);
50+
$prefix = $this->genericLinkProvider->getLinkPrefix($role);
51+
52+
return new ReferenceNode($reference, $referenceName ?? '', $interlinkData->interlink, self::TYPE, $prefix);
53+
}
54+
}

packages/guides/src/ReferenceResolvers/Interlink/InventoryLink.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(
2525
private string $path,
2626
private readonly string $title,
2727
) {
28-
if (preg_match('/^([a-zA-Z0-9-_.]+\/)*([a-zA-Z0-9-_.])+\.html(#[^#]*)?$/', $path) < 1) {
28+
if (preg_match('/^([a-zA-Z0-9-_.]+\/)*([a-zA-Z0-9-_.]+)(\.html)?(#[^#]*)?$/', $path) < 1) {
2929
throw new InvalidInventoryLink('Inventory link "' . $path . '" has an invalid scheme. ', 1_671_398_986);
3030
}
3131
}

packages/guides/tests/unit/Interlink/InventoryLinkTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ public function testLinkMayContaintDot(): void
5454
self::assertEquals($inventoryLink->getPath(), $link);
5555
}
5656

57-
public function testPhpLinkThrowsError(): void
58-
{
59-
$link = 'Some/Path/SomeThing.php#anchor';
60-
$this->expectException(InvalidInventoryLink::class);
61-
new InventoryLink('', '', $link, '');
62-
}
63-
6457
public function testJavaScriptLinkThrowsError(): void
6558
{
6659
$link = 'javascript:alert()';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- content start -->
2+
<div class="section" id="document-title">
3+
<h1>Document title</h1>
4+
5+
<p>See <a href="https://api.typo3.org/main/classes/TYPO3-CMS-Adminpanel-Controller-AjaxController.html">AjaxController</a> or
6+
<a href="https://api.typo3.org/main/classes/TYPO3-CMS-Adminpanel-Controller-MainController.html">that other controller</a>.</p>
7+
8+
</div>
9+
<!-- content end -->

0 commit comments

Comments
 (0)