Skip to content

Commit 01c5711

Browse files
authored
Merge pull request #915 from phpDocumentor/backport/1.x/pr-912
[1.x] Merge pull request #912 from phpDocumentor/bugfix/emphasize-lines
2 parents f0132eb + 51fd6e7 commit 01c5711

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

packages/guides-restructured-text/src/RestructuredText/Directives/OptionMapper/DefaultCodeNodeOptionMapper.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Psr\Log\LoggerInterface;
2222

2323
use function preg_match;
24+
use function sprintf;
2425
use function strval;
2526
use function trim;
2627

@@ -30,8 +31,8 @@
3031
*/
3132
final class DefaultCodeNodeOptionMapper implements CodeNodeOptionMapper
3233
{
33-
/** @see https://regex101.com/r/I3KttH/1 */
34-
public const LINE_NUMBER_RANGES_REGEX = '/^\d+(-\d+)?(?:,\s*\d+(-\d+)?)*$/';
34+
/** @see https://regex101.com/r/czvfnV/2 */
35+
public const LINE_NUMBER_RANGES_REGEX = '/^\d+(-\d*)?(?:,\s*\d+(-\d*)?)*$/';
3536

3637
public function __construct(
3738
private readonly LoggerInterface $logger,
@@ -79,7 +80,10 @@ private function setEmphasizeLinesBasedOnOptions(array $options, CodeNode $node,
7980
$emphasizeLines = (string) $options['emphasize-lines']->getValue();
8081
if (!preg_match(self::LINE_NUMBER_RANGES_REGEX, $emphasizeLines)) {
8182
// Input does not fit the pattern, log a warning
82-
$this->logger->warning('Invalid value for option emphasize-lines. Expected format: \'1-5, 7, 33\'', $blockContext->getLoggerInformation());
83+
$this->logger->warning(
84+
sprintf('Invalid value for option emphasize-lines: "%s". Expected format: \'1-5, 7, 33\'', $emphasizeLines),
85+
$blockContext->getLoggerInformation(),
86+
);
8387
}
8488
}
8589

tests/Integration/tests/code/code-block-emphasize/expected/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ <h1>Title</h1>
77
print(&#039;This line is highlighted.&#039;)
88
print(&#039;This one is not...&#039;)
99
print(&#039;...but this one is.&#039;)</code></pre>
10+
<pre><code class="language-yaml line-numbers" data-start="1" data-emphasize-lines="3-">Email:
11+
formEditor:
12+
predefinedDefaults:
13+
defaultValue: &#039;&#039;
14+
validators:
15+
-
16+
identifier: EmailAddress</code></pre>
1017
</div>
1118

1219
<!-- content end -->

tests/Integration/tests/code/code-block-emphasize/input/index.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,15 @@ Title
99
print('This line is highlighted.')
1010
print('This one is not...')
1111
print('...but this one is.')
12+
13+
.. code-block:: yaml
14+
:linenos:
15+
:emphasize-lines: 3-
16+
17+
Email:
18+
formEditor:
19+
predefinedDefaults:
20+
defaultValue: ''
21+
validators:
22+
-
23+
identifier: EmailAddress

0 commit comments

Comments
 (0)