Skip to content

Commit 603b9ea

Browse files
authored
Merge branch 'main' into task/complex-grid-table
2 parents 27c0dce + 4db1f1c commit 603b9ea

File tree

242 files changed

+6061
-5312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+6061
-5312
lines changed

packages/guides-restructured-text/resources/template/html/body/directive/confval.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<dl class="confval">
2-
<dt id="{{ node.id }}">
2+
<dt {%- if node.isNoindex == false %} id="{{ node.anchor }}"{% endif %}>
33
<code class="sig-name descname"><span class="pre">{{ node.plainContent }}</span></code></dt>
44
<dd>
55
<div class="line-block">

packages/guides-restructured-text/src/RestructuredText/Directives/ConfvalDirective.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(
4444
) {
4545
parent::__construct($startingRule);
4646

47-
$genericLinkProvider->addGenericLink(self::NAME, ConfvalNode::LINK_TYPE);
47+
$genericLinkProvider->addGenericLink(self::NAME, ConfvalNode::LINK_TYPE, ConfvalNode::LINK_PREFIX);
4848
}
4949

5050
public function getName(): string
@@ -83,6 +83,8 @@ protected function processSub(
8383
$type = $this->inlineParser->parse($directive->getOption('default')->toString(), $blockContext);
8484
}
8585

86+
$noindex = $directive->hasOption('noindex');
87+
8688
foreach ($directive->getOptions() as $option) {
8789
if (in_array($option->getName(), ['type', 'required', 'default', 'noindex', 'name'], true)) {
8890
continue;
@@ -91,6 +93,6 @@ protected function processSub(
9193
$additionalOptions[$option->getName()] = $this->inlineParser->parse($option->toString(), $blockContext);
9294
}
9395

94-
return new ConfvalNode($id, $directive->getData(), $type, $required, $default, $additionalOptions, $collectionNode->getChildren());
96+
return new ConfvalNode($id, $directive->getData(), $type, $required, $default, $additionalOptions, $collectionNode->getChildren(), $noindex);
9597
}
9698
}

packages/guides-restructured-text/src/RestructuredText/Directives/ContentsDirective.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function process(
5050

5151
return (new ContentMenuNode([new SectionMenuEntryNode($absoluteUrl)]))
5252
->withOptions($this->optionsToArray($options))
53-
->withCaption($directive->getDataNode());
53+
->withCaption($directive->getDataNode())
54+
->withLocal($directive->hasOption('local'));
5455
}
5556
}

packages/guides-restructured-text/src/RestructuredText/Nodes/ConfvalNode.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use phpDocumentor\Guides\Nodes\InlineCompoundNode;
1818
use phpDocumentor\Guides\Nodes\LinkTargetNode;
1919
use phpDocumentor\Guides\Nodes\Node;
20+
use phpDocumentor\Guides\Nodes\OptionalLinkTargetsNode;
21+
use phpDocumentor\Guides\Nodes\PrefixedLinkTargetNode;
2022

2123
/**
2224
* The confval directive configuration values.
@@ -25,9 +27,10 @@
2527
*
2628
* @extends CompoundNode<Node>
2729
*/
28-
final class ConfvalNode extends CompoundNode implements LinkTargetNode
30+
final class ConfvalNode extends CompoundNode implements LinkTargetNode, OptionalLinkTargetsNode, PrefixedLinkTargetNode
2931
{
3032
public const LINK_TYPE = 'std:confval';
33+
public const LINK_PREFIX = 'confval-';
3134

3235
/**
3336
* @param list<Node> $value
@@ -41,6 +44,7 @@ public function __construct(
4144
private readonly InlineCompoundNode|null $default = null,
4245
private readonly array $additionalOptions = [],
4346
array $value = [],
47+
private readonly bool $noindex = false,
4448
) {
4549
parent::__construct($value);
4650
}
@@ -60,6 +64,11 @@ public function getId(): string
6064
return $this->id;
6165
}
6266

67+
public function getAnchor(): string
68+
{
69+
return self::LINK_PREFIX . $this->id;
70+
}
71+
6372
public function getLinkText(): string
6473
{
6574
return $this->plainContent;
@@ -85,4 +94,14 @@ public function getAdditionalOptions(): array
8594
{
8695
return $this->additionalOptions;
8796
}
97+
98+
public function getPrefix(): string
99+
{
100+
return self::LINK_PREFIX;
101+
}
102+
103+
public function isNoindex(): bool
104+
{
105+
return $this->noindex;
106+
}
88107
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ final class GenericLinkProvider
3030
private array $textRoleLinkTypeMapping = [
3131
'ref' => SectionNode::STD_LABEL,
3232
];
33+
/** @var array<string, string> */
34+
private array $prefixLinkTypeMapping = ['ref' => ''];
3335

34-
public function addGenericLink(string $textRole, string $linkType): void
36+
public function addGenericLink(string $textRole, string $linkType, string $prefix = ''): void
3537
{
3638
$this->textRoleLinkTypeMapping[$textRole] = $linkType;
39+
$this->prefixLinkTypeMapping[$textRole] = $prefix;
3740
}
3841

3942
/** @return string[] */
@@ -46,4 +49,9 @@ public function getLinkType(string $textRole): string
4649
{
4750
return $this->textRoleLinkTypeMapping[$textRole] ?? SectionNode::STD_LABEL;
4851
}
52+
53+
public function getLinkPrefix(string $textRole): string
54+
{
55+
return $this->prefixLinkTypeMapping[$textRole] ?? '';
56+
}
4957
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ protected function createNode(string $referenceTarget, string|null $referenceNam
4646
$linkType = $this->genericLinkProvider->getLinkType($role);
4747
$interlinkData = $this->interlinkParser->extractInterlink($referenceTarget);
4848
$reference = $this->anchorReducer->reduceAnchor($interlinkData->reference);
49+
$prefix = $this->genericLinkProvider->getLinkPrefix($role);
4950

50-
return new ReferenceNode($reference, $referenceName ?? '', $interlinkData->interlink, $linkType);
51+
return new ReferenceNode($reference, $referenceName ?? '', $interlinkData->interlink, $linkType, $prefix);
5152
}
5253
}

packages/guides/src/Compiler/NodeTransformers/CollectLinkTargetsTransformer.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use phpDocumentor\Guides\Nodes\LinkTargetNode;
2222
use phpDocumentor\Guides\Nodes\MultipleLinkTargetsNode;
2323
use phpDocumentor\Guides\Nodes\Node;
24+
use phpDocumentor\Guides\Nodes\OptionalLinkTargetsNode;
25+
use phpDocumentor\Guides\Nodes\PrefixedLinkTargetNode;
2426
use phpDocumentor\Guides\Nodes\SectionNode;
2527
use phpDocumentor\Guides\ReferenceResolvers\AnchorNormalizer;
2628
use Psr\Log\LoggerInterface;
@@ -94,16 +96,26 @@ public function enterNode(Node $node, CompilerContext $compilerContext): Node
9496
}
9597

9698
if ($node instanceof LinkTargetNode) {
99+
if ($node instanceof OptionalLinkTargetsNode && $node->isNoindex()) {
100+
return $node;
101+
}
102+
97103
$currentDocument = $this->documentStack->top();
98104
Assert::notNull($currentDocument);
99105
$anchor = $this->anchorReducer->reduceAnchor($node->getId());
106+
$prefix = '';
107+
if ($node instanceof PrefixedLinkTargetNode) {
108+
$prefix = $node->getPrefix();
109+
}
110+
100111
$this->addLinkTargetToProject(
101112
$compilerContext,
102113
new InternalTarget(
103114
$currentDocument->getFilePath(),
104115
$anchor,
105116
$node->getLinkText(),
106117
$node->getLinkType(),
118+
$prefix,
107119
),
108120
);
109121
if ($node instanceof MultipleLinkTargetsNode) {

packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/ContentsMenuEntryNodeTransformer.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
namespace phpDocumentor\Guides\Compiler\NodeTransformers\MenuNodeTransformers;
1515

1616
use phpDocumentor\Guides\Compiler\CompilerContext;
17+
use phpDocumentor\Guides\Nodes\DocumentTree\SectionEntryNode;
1718
use phpDocumentor\Guides\Nodes\Menu\ContentMenuNode;
1819
use phpDocumentor\Guides\Nodes\Menu\MenuEntryNode;
1920
use phpDocumentor\Guides\Nodes\Menu\MenuNode;
2021
use phpDocumentor\Guides\Nodes\Menu\SectionMenuEntryNode;
2122
use phpDocumentor\Guides\Nodes\Node;
23+
use phpDocumentor\Guides\Nodes\SectionNode;
2224

2325
use function assert;
2426

@@ -45,12 +47,36 @@ protected function handleMenuEntry(MenuNode $currentMenu, MenuEntryNode $entryNo
4547
assert($entryNode instanceof SectionMenuEntryNode);
4648
$depth = (int) $currentMenu->getOption('depth', self::DEFAULT_MAX_LEVELS - 1) + 1;
4749
$documentEntry = $compilerContext->getDocumentNode()->getDocumentEntry();
48-
$newEntryNode = new SectionMenuEntryNode(
49-
$documentEntry->getFile(),
50-
$entryNode->getValue() ?? $documentEntry->getTitle(),
51-
1,
52-
);
53-
$this->addSubSectionsToMenuEntries($documentEntry, $newEntryNode, $depth);
50+
if ($currentMenu->isLocal()) {
51+
$sectionNode = $compilerContext->getShadowTree()->getParent()?->getParent()?->getNode();
52+
if (!$sectionNode instanceof SectionNode) {
53+
$this->logger->error('Section of contents directive not found. ', $compilerContext->getLoggerInformation());
54+
55+
return [];
56+
}
57+
58+
$sectionEntry = $documentEntry->findSectionEntry($sectionNode);
59+
if (!$sectionEntry instanceof SectionEntryNode) {
60+
$this->logger->error('Section of contents directive not found. ', $compilerContext->getLoggerInformation());
61+
62+
return [];
63+
}
64+
65+
$newEntryNode = new SectionMenuEntryNode(
66+
$documentEntry->getFile(),
67+
$entryNode->getValue() ?? $sectionEntry->getTitle(),
68+
1,
69+
$sectionEntry->getId(),
70+
);
71+
$this->addSubSections($newEntryNode, $sectionEntry, $documentEntry, 1, $depth);
72+
} else {
73+
$newEntryNode = new SectionMenuEntryNode(
74+
$documentEntry->getFile(),
75+
$entryNode->getValue() ?? $documentEntry->getTitle(),
76+
1,
77+
);
78+
$this->addSubSectionsToMenuEntries($documentEntry, $newEntryNode, $depth);
79+
}
5480

5581
return $newEntryNode->getSections();
5682
}

packages/guides/src/Meta/InternalTarget.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function __construct(
2424
protected string $anchorName,
2525
private readonly string|null $title = null,
2626
private readonly string $linkType = SectionNode::STD_LABEL,
27+
private readonly string $prefix = '',
2728
) {
2829
}
2930

@@ -63,4 +64,9 @@ public function getLinkType(): string
6364
{
6465
return $this->linkType;
6566
}
67+
68+
public function getPrefix(): string
69+
{
70+
return $this->prefix;
71+
}
6672
}

packages/guides/src/Nodes/DocumentTree/DocumentEntryNode.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace phpDocumentor\Guides\Nodes\DocumentTree;
1515

16+
use phpDocumentor\Guides\Nodes\SectionNode;
1617
use phpDocumentor\Guides\Nodes\TitleNode;
1718

1819
use function array_filter;
@@ -81,4 +82,22 @@ public function isRoot(): bool
8182
{
8283
return $this->isRoot;
8384
}
85+
86+
public function findSectionEntry(SectionNode $sectionNode): SectionEntryNode|null
87+
{
88+
foreach ($this->sections as $sectionEntryNode) {
89+
if ($sectionNode->getId() === $sectionEntryNode->getId()) {
90+
return $sectionEntryNode;
91+
}
92+
}
93+
94+
foreach ($this->sections as $sectionEntryNode) {
95+
$subsection = $sectionEntryNode->findSectionEntry($sectionNode);
96+
if ($subsection !== null) {
97+
return $subsection;
98+
}
99+
}
100+
101+
return null;
102+
}
84103
}

0 commit comments

Comments
 (0)