From 1f6fabc0b94363ff6acaf34ab7c04b1992f742e5 Mon Sep 17 00:00:00 2001 From: "lina.wolf" Date: Sat, 9 Mar 2024 07:39:41 +0100 Subject: [PATCH] [BUGFIX] Allow emphasize-lines with open end Sphinx also allows these Improve error message --- .../OptionMapper/DefaultCodeNodeOptionMapper.php | 10 +++++++--- .../code/code-block-emphasize/expected/index.html | 7 +++++++ .../tests/code/code-block-emphasize/input/index.rst | 12 ++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/guides-restructured-text/src/RestructuredText/Directives/OptionMapper/DefaultCodeNodeOptionMapper.php b/packages/guides-restructured-text/src/RestructuredText/Directives/OptionMapper/DefaultCodeNodeOptionMapper.php index 118f1cfe6..2d53be4a1 100644 --- a/packages/guides-restructured-text/src/RestructuredText/Directives/OptionMapper/DefaultCodeNodeOptionMapper.php +++ b/packages/guides-restructured-text/src/RestructuredText/Directives/OptionMapper/DefaultCodeNodeOptionMapper.php @@ -21,6 +21,7 @@ use Psr\Log\LoggerInterface; use function preg_match; +use function sprintf; use function strval; use function trim; @@ -30,8 +31,8 @@ */ final class DefaultCodeNodeOptionMapper implements CodeNodeOptionMapper { - /** @see https://regex101.com/r/I3KttH/1 */ - public const LINE_NUMBER_RANGES_REGEX = '/^\d+(-\d+)?(?:,\s*\d+(-\d+)?)*$/'; + /** @see https://regex101.com/r/czvfnV/2 */ + public const LINE_NUMBER_RANGES_REGEX = '/^\d+(-\d*)?(?:,\s*\d+(-\d*)?)*$/'; public function __construct( private readonly LoggerInterface $logger, @@ -79,7 +80,10 @@ private function setEmphasizeLinesBasedOnOptions(array $options, CodeNode $node, $emphasizeLines = (string) $options['emphasize-lines']->getValue(); if (!preg_match(self::LINE_NUMBER_RANGES_REGEX, $emphasizeLines)) { // Input does not fit the pattern, log a warning - $this->logger->warning('Invalid value for option emphasize-lines. Expected format: \'1-5, 7, 33\'', $blockContext->getLoggerInformation()); + $this->logger->warning( + sprintf('Invalid value for option emphasize-lines: "%s". Expected format: \'1-5, 7, 33\'', $emphasizeLines), + $blockContext->getLoggerInformation(), + ); } } diff --git a/tests/Integration/tests/code/code-block-emphasize/expected/index.html b/tests/Integration/tests/code/code-block-emphasize/expected/index.html index 6e8becf86..849d6add8 100644 --- a/tests/Integration/tests/code/code-block-emphasize/expected/index.html +++ b/tests/Integration/tests/code/code-block-emphasize/expected/index.html @@ -7,6 +7,13 @@

Title

print('This line is highlighted.') print('This one is not...') print('...but this one is.') +
Email:
+    formEditor:
+        predefinedDefaults:
+            defaultValue: ''
+            validators:
+                -
+                identifier: EmailAddress
diff --git a/tests/Integration/tests/code/code-block-emphasize/input/index.rst b/tests/Integration/tests/code/code-block-emphasize/input/index.rst index 8037dacb4..3f591be7e 100644 --- a/tests/Integration/tests/code/code-block-emphasize/input/index.rst +++ b/tests/Integration/tests/code/code-block-emphasize/input/index.rst @@ -9,3 +9,15 @@ Title print('This line is highlighted.') print('This one is not...') print('...but this one is.') + +.. code-block:: yaml + :linenos: + :emphasize-lines: 3- + + Email: + formEditor: + predefinedDefaults: + defaultValue: '' + validators: + - + identifier: EmailAddress