Skip to content

Commit 0b31b3c

Browse files
committed
fix: better parse end of {@link ...} blocks
1 parent d7aaa0a commit 0b31b3c

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/Renderer/TwigExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ public function parseDesc(array $context, ?string $desc, Reflection $classOrFunc
154154
$desc = str_replace(['<code>', '</code>'], ['```', '```'], $desc);
155155

156156
$desc = (string) preg_replace_callback(
157-
'/@see ([^ ]+)/',
157+
'/@see ([^ ]+)/', // Match until a whitespace is found
158158
function ($match) use (&$classOrFunctionRefl): string {
159159
return $this->transformContentsIntoLinks($match[1], $classOrFunctionRefl);
160160
},
161161
$desc
162162
);
163163

164164
$desc = (string) preg_replace_callback(
165-
'/\{@link ((?!\})(?<contents>[^ ]+))/',
165+
'/\{@link (?!\})(?<contents>[^\r\n\t\f]+)\}/',
166166
function (array $match) use (&$classOrFunctionRefl): string {
167167
$data = rtrim($match['contents'], '}');
168168
return $this->transformContentsIntoLinks($data, $classOrFunctionRefl);

tests/Renderer/TwigExtensionTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,22 @@ public function dataProviderParseDesc(): array
3535
'<p><p>text</p></p>',
3636
'<p><p>text</p></p>'
3737
],
38+
[
39+
'Constructor. Set DB Object and set {@link $return_statements return_statements}.',
40+
'<p>Constructor. Set DB Object and set $return_statements return_statements.</p>'
41+
],
42+
[
43+
'Constructor. Set DB Object and set {@link $return_statements return_statements}',
44+
'<p>Constructor. Set DB Object and set $return_statements return_statements</p>'
45+
],
3846
[
3947
'Hi {@link \PDO}',
4048
'<p>Hi \PDO</p>'
4149
],
50+
[
51+
'Hi {@link https://doctum.long-term.support}',
52+
'<p>Hi <a href="https://doctum.long-term.support">https://doctum.long-term.support</a></p>'
53+
],
4254
[
4355
'Hi {@link \PDO}',
4456
'<p>Hi <a href="https://www.php.net/PDO">PDO</a></p>',
@@ -219,6 +231,11 @@ public function dataProviderTransformContentsIntoLinks(): array
219231
$ref4->setProject($project);
220232
$project->addClass($ref4);
221233
return [
234+
[
235+
'https://doctum.long-term.support',
236+
'https://doctum.long-term.support',
237+
$ref
238+
],
222239
[
223240
'\PDO',
224241
'[PDO](https://www.php.net/PDO)',
@@ -274,6 +291,16 @@ public function dataProviderTransformContentsIntoLinks(): array
274291
'my_class',
275292
new ClassReflection('my_class', 0)
276293
],
294+
[
295+
'$return_statements return_statements.',
296+
'$return_statements return_statements.',
297+
new ClassReflection('my_class', 0)
298+
],
299+
[
300+
'$return_statements return_statements',
301+
'$return_statements return_statements',
302+
new ClassReflection('my_class', 0)
303+
],
277304
];
278305
}
279306

0 commit comments

Comments
 (0)