diff --git a/packages/guides-restructured-text/src/RestructuredText/Parser/References/EmbeddedReferenceParser.php b/packages/guides-restructured-text/src/RestructuredText/Parser/References/EmbeddedReferenceParser.php index bc6b294d6..a91efc197 100644 --- a/packages/guides-restructured-text/src/RestructuredText/Parser/References/EmbeddedReferenceParser.php +++ b/packages/guides-restructured-text/src/RestructuredText/Parser/References/EmbeddedReferenceParser.php @@ -14,14 +14,15 @@ namespace phpDocumentor\Guides\RestructuredText\Parser\References; use function preg_match; +use function str_replace; use function trim; trait EmbeddedReferenceParser { /** - * https://regex101.com/r/KadqKx/1 + * https://regex101.com/r/8O8N3h/2 */ - private string $referenceRegex = '/^(.*?)(<([^<]+)>)?$/s'; + private string $referenceRegex = '/^(.*?)((?)?$/s'; private function extractEmbeddedReference(string $text): ReferenceData { @@ -37,6 +38,9 @@ private function extractEmbeddedReference(string $text): ReferenceData $text = null; } - return new ReferenceData($reference, $text); + return new ReferenceData( + str_replace(['\\<', '\\>'], ['<', '>'], $reference), + $text, + ); } } diff --git a/packages/guides-restructured-text/tests/unit/Parser/InlineTokenParserTest.php b/packages/guides-restructured-text/tests/unit/Parser/InlineTokenParserTest.php index a686f4e87..ce43a3dfc 100644 --- a/packages/guides-restructured-text/tests/unit/Parser/InlineTokenParserTest.php +++ b/packages/guides-restructured-text/tests/unit/Parser/InlineTokenParserTest.php @@ -174,6 +174,10 @@ public static function inlineNodeProvider(): array '`myref`_', new InlineCompoundNode([new HyperLinkNode('myref', 'myref')]), ], + 'Named Reference, escaped phrase' => [ + '`myref \`_', + new InlineCompoundNode([new HyperLinkNode('myref ', 'myref ')]), + ], 'Named Reference, Phrased, With URL' => [ '`myref `_', new InlineCompoundNode([new HyperLinkNode('myref', 'https://test.com')]), diff --git a/tests/Integration/tests/references/reference-with-escape/expected/index.html b/tests/Integration/tests/references/reference-with-escape/expected/index.html index 9d090baf3..9705a6a5e 100644 --- a/tests/Integration/tests/references/reference-with-escape/expected/index.html +++ b/tests/Integration/tests/references/reference-with-escape/expected/index.html @@ -8,9 +8,7 @@

the <head>

- - -

See also the <head> of this file or the <head>.

+

See also this is a complex reference the <head>.

diff --git a/tests/Integration/tests/references/reference-with-escape/input/index.rst b/tests/Integration/tests/references/reference-with-escape/input/index.rst index 7e54678d0..2397cd0c3 100644 --- a/tests/Integration/tests/references/reference-with-escape/input/index.rst +++ b/tests/Integration/tests/references/reference-with-escape/input/index.rst @@ -1,6 +1,4 @@ -.. _anchor: - -the \ +the ============ -See also :ref:`the \ of this file ` or `the \`_. +See also this is a complex reference `the \`_. diff --git a/tests/Integration/tests/references/reference-with-escape/input/skip b/tests/Integration/tests/references/reference-with-escape/input/skip deleted file mode 100644 index aa90bef0f..000000000 --- a/tests/Integration/tests/references/reference-with-escape/input/skip +++ /dev/null @@ -1 +0,0 @@ -Named phrases don't render escape characters correctly