diff --git a/packages/guides-restructured-text/src/RestructuredText/Parser/InlineLexer.php b/packages/guides-restructured-text/src/RestructuredText/Parser/InlineLexer.php index 25a6a96bd..267ea06c9 100644 --- a/packages/guides-restructured-text/src/RestructuredText/Parser/InlineLexer.php +++ b/packages/guides-restructured-text/src/RestructuredText/Parser/InlineLexer.php @@ -130,7 +130,7 @@ protected function getType(string &$value) return self::ANONYMOUSE_REFERENCE; } - if (preg_match('/[a-z0-9-]+_{1}/i', $value)) { + if (preg_match('/[a-z0-9-]+_{1}(?=\s|$)/i', $value)) { return self::NAMED_REFERENCE; } diff --git a/packages/guides-restructured-text/tests/unit/Parser/InlineLexerTest.php b/packages/guides-restructured-text/tests/unit/Parser/InlineLexerTest.php new file mode 100644 index 000000000..aac6368e6 --- /dev/null +++ b/packages/guides-restructured-text/tests/unit/Parser/InlineLexerTest.php @@ -0,0 +1,57 @@ +setInput($input); + $lexer->moveNext(); + $lexer->moveNext(); + foreach ($result as $tokenType) { + assertEquals($tokenType, $lexer->token?->type); + } + } + + /** @return array> */ + public static function inlineLexerProvider(): array + { + return [ + 'Backtick' => [ + '`', + [InlineLexer::BACKTICK], + ], + 'Normal Url' => [ + 'http://www.test.com', + [InlineLexer::HYPERLINK], + ], + 'HTTPS Url' => [ + 'https://www.test.com', + [InlineLexer::HYPERLINK], + ], + 'String with underscore' => [ + 'EXT:css_styled_content/static/v6.2', + [InlineLexer::WORD], + ], + 'Named Reference' => [ + 'css_', + [InlineLexer::NAMED_REFERENCE], + ], + 'Named Reference in sentence' => [ + 'css_ and something', + [InlineLexer::NAMED_REFERENCE], + ], + ]; + } +}