From 4ca97e091c73d997c2ce1a7920a4d96e742be3ac Mon Sep 17 00:00:00 2001 From: "lina.wolf" Date: Tue, 4 Feb 2025 18:24:04 +0100 Subject: [PATCH] [BUGFIX] Improve line breaking issues for tables references https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-CoreApi/issues/4791 --- .../body/directive/typo3-file.html.twig | 12 +++---- ...chFileObjectsToFileTextRoleTransformer.php | 13 ++++++++ .../src/Directives/Typo3FileDirective.php | 5 ++- .../src/Nodes/Typo3FileNode.php | 6 ---- .../ObjectsInventory/FileObject.php | 2 -- .../tests/typo3-file/expected/index.html | 33 ++++++++++++------- .../tests/typo3-file/input/index.rst | 6 ++-- 7 files changed, 44 insertions(+), 33 deletions(-) diff --git a/packages/typo3-docs-theme/resources/template/body/directive/typo3-file.html.twig b/packages/typo3-docs-theme/resources/template/body/directive/typo3-file.html.twig index d14e1f1a9..0c592c26a 100644 --- a/packages/typo3-docs-theme/resources/template/body/directive/typo3-file.html.twig +++ b/packages/typo3-docs-theme/resources/template/body/directive/typo3-file.html.twig @@ -1,9 +1,9 @@ -
-

{{ node.path }}{{ node.plainContent }}

+

{{ node.composerPath }}{{ node.plainContent }}

@@ -31,17 +31,13 @@
Scope
{{ node.scope }}
{% endif -%} - {% if node.path %} -
Path
-
{{ node.path }}{{ node.plainContent }}
- {% endif -%} {% if node.composerPathPrefix or node.composerPath %}
Path (Composer)
-
{{ node.composerPathPrefix }}{{ node.composerPath }}{{ node.path }}{{ node.plainContent }}
+
{{ node.composerPathPrefix }}{{ node.composerPath }}{{ node.plainContent }}
{% endif -%} {%- if node.classicPathPrefix or node.classicPath %}
Path (Classic)
-
{{ node.classicPathPrefix }}{{ node.classicPath }}{{ node.path }}{{ node.plainContent }}
+
{{ node.classicPathPrefix }}{{ node.classicPath }}{{ node.plainContent }}
{% endif -%} {% if node.configuration %}
Configuration
diff --git a/packages/typo3-docs-theme/src/Compiler/NodeTransformers/AttachFileObjectsToFileTextRoleTransformer.php b/packages/typo3-docs-theme/src/Compiler/NodeTransformers/AttachFileObjectsToFileTextRoleTransformer.php index cf1064744..0f80d121d 100644 --- a/packages/typo3-docs-theme/src/Compiler/NodeTransformers/AttachFileObjectsToFileTextRoleTransformer.php +++ b/packages/typo3-docs-theme/src/Compiler/NodeTransformers/AttachFileObjectsToFileTextRoleTransformer.php @@ -35,6 +35,19 @@ public function enterNode(Node $node, CompilerContextInterface $compilerContext) } /** @var DataObject[] $fileObjects */ $fileObjects = $this->objectInventory->getGroup(FileObject::KEY); + foreach ($fileObjects as $fileObject) { + if (!$fileObject instanceof FileObject) { + continue; + } + if ($fileObject->id === $node->getFileLink()) { + $node->setFileObject($fileObject); + return $node; + } + if (preg_match($fileObject->regex, $node->getFileLink())) { + $node->setFileObject($fileObject); + break; + } + } foreach ($fileObjects as $fileObject) { if (!$fileObject instanceof FileObject) { continue; diff --git a/packages/typo3-docs-theme/src/Directives/Typo3FileDirective.php b/packages/typo3-docs-theme/src/Directives/Typo3FileDirective.php index 608ddb579..c68ea4b0c 100644 --- a/packages/typo3-docs-theme/src/Directives/Typo3FileDirective.php +++ b/packages/typo3-docs-theme/src/Directives/Typo3FileDirective.php @@ -82,10 +82,9 @@ protected function processSub( id: $key, fileName: $filename, language: $language, - path: $this->getPath($path), - composerPath: $this->getPath($directive->getOptionString('composerPath')), + composerPath: $directive->hasOption('composerPath') ? $this->getPath($directive->getOptionString('composerPath')) : $this->getPath($path), composerPathPrefix: $this->getPath($pathPrefix), - classicPath: $this->getPath($directive->getOptionString('classicPath')), + classicPath: $directive->hasOption('classicPath') ? $this->getPath($directive->getOptionString('classicPath')) : $this->getPath($path), classicPathPrefix: $this->getPath($classicPathPrefix), scope: $directive->getOptionString('scope'), regex: $regex, diff --git a/packages/typo3-docs-theme/src/Nodes/Typo3FileNode.php b/packages/typo3-docs-theme/src/Nodes/Typo3FileNode.php index 92c2451e1..d21ac31b9 100644 --- a/packages/typo3-docs-theme/src/Nodes/Typo3FileNode.php +++ b/packages/typo3-docs-theme/src/Nodes/Typo3FileNode.php @@ -22,7 +22,6 @@ public function __construct( private readonly string $id, private readonly string $fileName, private readonly string $language, - private readonly string $path, private readonly string $composerPath = '', private readonly string $composerPathPrefix = '', private readonly string $classicPath = '', @@ -53,11 +52,6 @@ public function getLanguage(): string return $this->language; } - public function getPath(): string - { - return $this->path; - } - public function getClassicPath(): string { return $this->classicPath; diff --git a/packages/typo3-docs-theme/src/ReferenceResolvers/ObjectsInventory/FileObject.php b/packages/typo3-docs-theme/src/ReferenceResolvers/ObjectsInventory/FileObject.php index 6b1e07c0c..fe2e91d85 100644 --- a/packages/typo3-docs-theme/src/ReferenceResolvers/ObjectsInventory/FileObject.php +++ b/packages/typo3-docs-theme/src/ReferenceResolvers/ObjectsInventory/FileObject.php @@ -10,7 +10,6 @@ class FileObject implements DataObject public function __construct( public string $fileName, public string $language, - public string $path, public string $composerPath = '', public string $composerPathPrefix = '', public string $classicPath = '', @@ -26,7 +25,6 @@ public static function fromTypo3Node(Typo3FileNode $node): FileObject return new FileObject( $node->getFileName(), $node->getLanguage(), - $node->getPath(), $node->getComposerPath(), $node->getComposerPathPrefix(), $node->getClassicPath(), diff --git a/tests/Integration/tests/typo3-file/expected/index.html b/tests/Integration/tests/typo3-file/expected/index.html index 3435e06b4..daac6fdb1 100644 --- a/tests/Integration/tests/typo3-file/expected/index.html +++ b/tests/Integration/tests/typo3-file/expected/index.html @@ -54,7 +54,7 @@

Configuration/page.tsconfig

data-bs-toggle="modal" data-bs-target="#linkReferenceModal" data-id="file-extension-configuration-page-tsconfig" - data-rstCode=":file:`packages/my_extension/page.tsconfig`" + data-rstCode=":file:`packages/my_extension/Configuration/page.tsconfig`" title="Reference this file definition"> @@ -63,8 +63,6 @@

Configuration/page.tsconfig

Scope
extension
-
Path
-
Configuration/page.tsconfig
Path (Composer)
packages/my_extension/Configuration/page.tsconfig
Path (Classic)
@@ -79,12 +77,12 @@

Configuration/page.tsconfig

-
-

settings.php

+

config/system/settings.php

@@ -117,12 +115,12 @@

settings.php

-
-

ENABLE_INSTALL_TOOL

+

config/ENABLE_INSTALL_TOOL

@@ -154,12 +152,12 @@

ENABLE_INSTALL_TOOL

-
-

LOCK_BACKEND

+

var/lock/LOCK_BACKEND

@@ -238,12 +236,12 @@

config.yaml

-
-

SomeClass.php

+

Classes/SomeClass.php

@@ -368,6 +366,19 @@

Linking filesConfiguration File
  • Unknown/File.xyz
  • FILE:EXT:Unknown/File.xyz
  • +
  • SomeClass.php
  • diff --git a/tests/Integration/tests/typo3-file/input/index.rst b/tests/Integration/tests/typo3-file/input/index.rst index 89e92d98c..dd83e6623 100644 --- a/tests/Integration/tests/typo3-file/input/index.rst +++ b/tests/Integration/tests/typo3-file/input/index.rst @@ -54,10 +54,9 @@ TYPO3 Files :regex: /.*Configuration\/Sets\/[^\/]+\/config\.yaml$/ .. typo3:file:: SomeClass.php - :path: / + :name: classes-someclass-php :scope: extension - :composerPath: /Classes/ - :classicPath: /Classes/ + :path: /Classes/ :regex: /^.*Classes\/.*\.php/ :shortDescription: PHP Classes in this file get auto-loaded @@ -73,6 +72,7 @@ Linking files * :file:`Configuration File ` * :file:`Unknown/File.xyz` * :file:`FILE:EXT:Unknown/File.xyz` +* :file:`SomeClass.php ` Code Block captions ===================