Skip to content

Commit 2b1f9c6

Browse files
committed
[TASK] Allow to omit whitespace before reference target
While reST expects a whitespace here, Sphinx allows to omit the whitespace and still interprets them correctly.
1 parent c01ea7d commit 2b1f9c6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/RestructuredText/Parser/References/EmbeddedReferenceParser.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,25 @@
1414
namespace phpDocumentor\Guides\RestructuredText\Parser\References;
1515

1616
use function preg_match;
17+
use function trim;
1718

1819
trait EmbeddedReferenceParser
1920
{
21+
/**
22+
* https://regex101.com/r/KadqKx/1
23+
*/
24+
private string $referenceRegex = '/^(.*?)(<([^<]+)>)?$/s';
25+
2026
private function extractEmbeddedReference(string $text): ReferenceData
2127
{
22-
preg_match('/^(.*?)(?:(?:\s|^)<([^<]+)>)?$/s', $text, $matches);
28+
preg_match($this->referenceRegex, $text, $matches);
2329

24-
$text = $matches[1] === '' ? null : $matches[1];
25-
$reference = $matches[1];
30+
$text = $matches[1] === '' ? null : trim($matches[1]);
31+
$reference = trim($matches[1]);
2632

27-
if (isset($matches[2])) {
33+
if (isset($matches[3])) {
2834
// there is an embedded URI, text and URI are different
29-
$reference = $matches[2];
35+
$reference = $matches[3];
3036
} else {
3137
$text = null;
3238
}

0 commit comments

Comments
 (0)