Skip to content

[BUGFIX] Allow emphasize-lines with open end #912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Psr\Log\LoggerInterface;

use function preg_match;
use function sprintf;
use function strval;
use function trim;

Expand All @@ -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,
Expand Down Expand Up @@ -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(),
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ <h1>Title</h1>
print(&#039;This line is highlighted.&#039;)
print(&#039;This one is not...&#039;)
print(&#039;...but this one is.&#039;)</code></pre>
<pre><code class="language-yaml line-numbers" data-start="1" data-emphasize-lines="3-">Email:
formEditor:
predefinedDefaults:
defaultValue: &#039;&#039;
validators:
-
identifier: EmailAddress</code></pre>
</div>

<!-- content end -->
12 changes: 12 additions & 0 deletions tests/Integration/tests/code/code-block-emphasize/input/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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