Skip to content

Commit f2be08d

Browse files
committed
Fix escape chars in references
1 parent dd4d374 commit f2be08d

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

packages/guides-restructured-text/src/RestructuredText/Parser/References/EmbeddedReferenceParser.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
namespace phpDocumentor\Guides\RestructuredText\Parser\References;
1515

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

1920
trait EmbeddedReferenceParser
2021
{
2122
/**
22-
* https://regex101.com/r/KadqKx/1
23+
* https://regex101.com/r/8O8N3h/2
2324
*/
24-
private string $referenceRegex = '/^(.*?)(<([^<]+)>)?$/s';
25+
private string $referenceRegex = '/^(.*?)((?<!\\\\)<([^<]+)(?<!\\\\)>)?$/s';
2526

2627
private function extractEmbeddedReference(string $text): ReferenceData
2728
{
@@ -37,6 +38,9 @@ private function extractEmbeddedReference(string $text): ReferenceData
3738
$text = null;
3839
}
3940

40-
return new ReferenceData($reference, $text);
41+
return new ReferenceData(
42+
str_replace(['\\<', '\\>'], ['<', '>'], $reference),
43+
$text,
44+
);
4145
}
4246
}

packages/guides-restructured-text/tests/unit/Parser/InlineTokenParserTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ public static function inlineNodeProvider(): array
174174
'`myref`_',
175175
new InlineCompoundNode([new HyperLinkNode('myref', 'myref')]),
176176
],
177+
'Named Reference, escaped phrase' => [
178+
'`myref \<foo\>`_',
179+
new InlineCompoundNode([new HyperLinkNode('myref <foo>', 'myref <foo>')]),
180+
],
177181
'Named Reference, Phrased, With URL' => [
178182
'`myref <https://test.com>`_',
179183
new InlineCompoundNode([new HyperLinkNode('myref', 'https://test.com')]),

tests/Integration/tests/references/reference-with-escape/expected/index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
<!-- content start -->
99
<div class="section" id="the-head">
1010
<h1>the &lt;head&gt;</h1>
11-
12-
<a id="anchor"></a>
13-
<p>See also <a href="/index.html#anchor">the &lt;head&gt; of this file</a> or <a href="/index.html#the-head">the &lt;head&gt;</a>.</p>
11+
<p>See also this is a complex reference <a href="/index.html#the-head">the &lt;head&gt;</a>.</p>
1412
</div>
1513

1614
<!-- content end -->
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
.. _anchor:
2-
3-
the \<head\>
1+
the <head>
42
============
53

6-
See also :ref:`the \<head\> of this file <anchor>` or `the \<head\>`_.
4+
See also this is a complex reference `the \<head\>`_.

tests/Integration/tests/references/reference-with-escape/input/skip

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)