Skip to content

Commit 3e199fc

Browse files
authored
[TASK] Use "Line Break Opportunity" tags in confvals (#726)
Resolves #719
1 parent 05e5470 commit 3e199fc

File tree

27 files changed

+248
-217
lines changed

27 files changed

+248
-217
lines changed

Documentation-rendertest/Confval/ConfvalTrees.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Long default values
8484
.. confval:: pages
8585
:name: typoscript-pages
8686
:type: string
87-
:default: {$styles.content.loginform.pid}
87+
:default: `{$styles.content.loginform.pid}`
8888
:test: `1`
8989

9090
Define the User Storage Page with the Website User Records, using a
@@ -93,7 +93,7 @@ Long default values
9393
.. confval:: redirectPageLoginError
9494
:name: typoscript-redirectPageLoginError
9595
:type: integer
96-
:default: {$styles.content.loginform.redirectPageLoginError}
96+
:default: `{$styles.content.loginform.redirectPageLoginError}`
9797

9898
Page id to redirect to after Login Error
9999

@@ -108,7 +108,7 @@ Long default values
108108
.. confval:: email.templateRootPaths
109109
:name: typoscript-email.templateRootPaths
110110
:type: array
111-
:default: {$styles.content.loginform.email.templateRootPaths}
111+
:default: `{$styles.content.loginform.email.templateRootPaths}`
112112

113113
Path to template directory used for emails
114114

Documentation-rendertest/PhpDomain/Index.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,32 +469,32 @@ Return Types
469469
.. php:method:: returnClassFromSameNamespace()
470470
471471
:returns: An object instance of a class from the same namespace.
472-
:returntype: OtherLibrary\\ReturnedClass
472+
:returntype: `OtherLibrary\\ReturnedClass`
473473

474474
.. php:method:: returnClassFromOtherNamespace()
475475
476476
:returns: An object instance of a class from another namespace.
477-
:returntype: LibraryName\\SubPackage\\SubpackageInterface
477+
:returntype: `LibraryName\\SubPackage\\SubpackageInterface`
478478

479479
.. php:method:: returnClassConstant()
480480
481481
:returns: The value of a specific class constant.
482-
:returntype: LibraryName\\NamespaceClass::NAMESPACE_CONST
482+
:returntype: `LibraryName\\NamespaceClass::NAMESPACE_CONST`
483483

484484
.. php:method:: returnGlobalConstant()
485485
486486
:returns: The value of a specific global constant.
487-
:returntype: SOME_CONSTANT
487+
:returntype: `SOME_CONSTANT`
488488

489489
.. php:method:: returnExceptionInstance()
490490
491491
:returns: An instance of an exception.
492-
:returntype: InvalidArgumentException
492+
:returntype: `InvalidArgumentException`
493493

494494
.. php:method:: returnScalarType()
495495
496496
:returns: A scalar string type.
497-
:returntype: string
497+
:returntype: `string`
498498

499499
.. php:method:: returnUnionType()
500500
@@ -533,6 +533,6 @@ Instance of this interface is returned by.
533533
:param integer $end: End angle.
534534
:param Imagine\Image\Color $color: Line color.
535535

536-
:throws: Imagine\Exception\RuntimeException
536+
:throws: `Imagine\Exception\RuntimeException`
537537

538-
:returns: Imagine\Draw\DrawerInterface
538+
:returns: `Imagine\Draw\DrawerInterface`

composer.lock

Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/typo3-docs-theme/resources/template/body/directive/confval-menu.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{% endif %}
99
{% endfor %}
1010
<div class="label">
11-
<a href="#{{ entry.anchor }}">{{ entry.plainContent }}</a>
11+
<a href="#{{ entry.anchor }}">{{ replaceLineBreakOpportunityTags(entry.plainContent) }}</a>
1212
{% for fieldName, field in node.fields %}
1313
{% if fieldName=='type' %}
1414
, Type: {{ renderNode(entry.type) }}
@@ -60,7 +60,7 @@
6060
</div>
6161
{% endif %}
6262
<div class="label">
63-
<a href="#{{ entry.anchor }}">{{ entry.plainContent }}</a>
63+
<a href="#{{ entry.anchor }}">{{ replaceLineBreakOpportunityTags(entry.plainContent) }}</a>
6464
{% for fieldName, field in node.fields %}
6565
{% if fieldName=='type' %}
6666
, Type: {{ renderNode(entry.type) }}
@@ -89,7 +89,7 @@
8989

9090
{% macro renderConfvalRow(entry, node, level) %}
9191
<tr>
92-
<td><div class="confval-label ps-{{ level * 2 }}"><a href="#{{ entry.anchor }}">{{ entry.plainContent }}</a></div></td>
92+
<td><div class="confval-label ps-{{ level * 2 }}"><a href="#{{ entry.anchor }}">{{ replaceLineBreakOpportunityTags(entry.plainContent) }}</a></div></td>
9393
{% for fieldName, field in node.fields %}
9494
<td>
9595
{% if fieldName=='type' %}

packages/typo3-docs-theme/resources/template/body/directive/confval.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<dl class="confval">
22
<dt{% if not node.noindex %} id="{{ node.anchor }}"{% endif %} class="d-flex justify-content-between">
33
<div class="confval-header">
4-
<code class="sig-name descname"><span class="pre">{{ node.plainContent }}</span></code>
4+
<code class="sig-name descname"><span class="pre">{{ replaceLineBreakOpportunityTags(node.plainContent) }}</span></code>
55
{% if not node.noindex %}
66
<a class="headerlink" href="#{{ node.anchor }}" data-bs-toggle="modal" data-bs-target="#linkReferenceModal" data-id="{{ node.anchor }}" data-rstCode="{{ getRstCodeForLink(node) }}" title="Reference this configuration value">¶</a>
77
{% else %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<span class="sig-name descname"><span class="pre">{{ replaceLineBreakOpportunityTags(node.name) }}</span></span>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<span class="pre">{{ replaceLineBreakOpportunityTags(code) }}</span>

packages/typo3-docs-theme/resources/template/inline/textroles/code.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
data-bs-html="true">
77
{%- if node.info.url %}
88
<a href="{{ node.info['url'] }}" target="_blank">
9-
{{- node.value }} <span class="text-secondary"><i class="fa-regular fa-circle-question"></i></span></a>
9+
{{- replaceLineBreakOpportunityTags(node.value) }} <span class="text-secondary"><i class="fa-regular fa-circle-question"></i></span></a>
1010
{%- else -%}
11-
{{ node.value }}
11+
{{ replaceLineBreakOpportunityTags(node.value) }}
1212
{%- endif -%}
1313
</code>
1414
{% endapply %}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{% apply spaceless %}
2-
<code class="code-inline file" translate="no" title="File path">{{ node.value }}</code>
2+
<code class="code-inline file" translate="no" title="File path">{{ replaceLineBreakOpportunityTags(node.value) }}</code>
33
{% endapply %}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{% apply spaceless %}
2-
<code class="code-inline path" translate="no" title="Path">{{ node.value }}</code>
2+
<code class="code-inline path" translate="no" title="Path">{{ replaceLineBreakOpportunityTags(node.value) }}</code>
33
{% endapply %}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{% apply spaceless %}
2-
<code class="code-inline">{{ node.value }}</code>
2+
<code class="code-inline">{{ replaceLineBreakOpportunityTags(node.value) }}</code>
33
{% endapply %}

packages/typo3-docs-theme/src/Parser/ExtendedInterlinkParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public function extractInterlink(string $fullReference): InterlinkData
2020
return new InterlinkData($fullReference, '');
2121
}
2222

23-
return new InterlinkData($matches[2], $matches[1] ?? '');
23+
return new InterlinkData($matches[2], $matches[1]);
2424
}
2525
}

packages/typo3-docs-theme/src/TextRoles/CustomLinkTextRole.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,20 @@ protected function createNode(DocumentParserContext $documentParserContext, stri
6464
private function extractEmbeddedUri(string $text): array
6565
{
6666
preg_match(self::TEXTROLE_LINK_REGEX, $text, $matches);
67+
$description = null;
68+
$uri = $text;
69+
if (isset($matches[1]) && is_string($matches[1])) {
70+
$description = $matches[1] === '' ? null : $matches[1];
71+
$uri = $matches[1];
72+
}
6773

68-
$text = $matches[1] === '' ? null : $matches[1];
69-
$uri = $matches[1];
70-
71-
if (isset($matches[2])) {
74+
if (isset($matches[2]) && is_string($matches[2])) {
7275
// there is an embedded URI, text and URI are different
7376
$uri = $matches[2];
7477
} else {
75-
$text = null;
78+
$description = null;
7679
}
7780

78-
return ['text' => $text, 'uri' => $uri];
81+
return ['text' => $description, 'uri' => $uri];
7982
}
8083
}

packages/typo3-docs-theme/src/Twig/TwigExtension.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@
3434

3535
final class TwigExtension extends AbstractExtension
3636
{
37+
/**
38+
* @see https://regex101.com/r/qWKenb/1
39+
*/
40+
public const CAMEL_CASE_BREAK_REGEX = '/([a-z])([A-Z])/';
41+
42+
/**
43+
* @see https://regex101.com/r/nxExYM/2
44+
*/
45+
public const NON_LETTER_BREAK_REGEX = '/(?<!^)([.\_\-\\\\\/:])([a-zA-Z0-9])/';
46+
47+
/**
48+
* @see https://regex101.com/r/uIul8d/1
49+
*/
50+
public const BRACKETS_BREAK_REGEX = '/(?<!^)([\[\(\{\<\|])/';
51+
3752
private string $typo3AzureEdgeURI = '';
3853

3954
public function __construct(
@@ -75,8 +90,19 @@ public function getFunctions(): array
7590
new TwigFunction('getStandardInventories', $this->getStandardInventories(...), ['is_safe' => ['html'], 'needs_context' => true]),
7691
new TwigFunction('getRstCodeForLink', $this->getRstCodeForLink(...), ['is_safe' => [], 'needs_context' => true]),
7792
new TwigFunction('isRenderedForDeployment', $this->isRenderedForDeployment(...)),
93+
new TwigFunction('replaceLineBreakOpportunityTags', $this->replaceLineBreakOpportunityTags(...), ['is_safe' => ['html'], 'needs_context' => false]),
7894
];
7995
}
96+
public function replaceLineBreakOpportunityTags(string $value): string
97+
{
98+
// as the result is html safe
99+
$brokenValue = htmlspecialchars($value);
100+
$brokenValue = preg_replace(self::BRACKETS_BREAK_REGEX, '<wbr>$1', $brokenValue);
101+
$brokenValue = preg_replace(self::CAMEL_CASE_BREAK_REGEX, '$1<wbr>$2', $brokenValue ?? $value);
102+
$brokenValue = preg_replace(self::NON_LETTER_BREAK_REGEX, '$1<wbr>$2', $brokenValue ?? $value);
103+
$brokenValue = preg_replace(self::NON_LETTER_BREAK_REGEX, '$1<wbr>$2', $brokenValue ?? $value);
104+
return $brokenValue ?? $value;
105+
}
80106

81107
public function renderPlainText(mixed $value): string
82108
{

0 commit comments

Comments
 (0)