Skip to content

Comments

Add line numbers and line highlighting for code blocks#82

Draft
dereuromark wants to merge 1 commit intomasterfrom
feature/code-block-line-numbers
Draft

Add line numbers and line highlighting for code blocks#82
dereuromark wants to merge 1 commit intomasterfrom
feature/code-block-line-numbers

Conversation

@dereuromark
Copy link
Contributor

Summary

  • Add VitePress-inspired syntax for code block line numbers and line highlighting
  • Shorthand # syntax for line numbers (cleaner than :line-numbers)
  • Support for line number offset with #=N
  • Support for line highlighting with {1,3-5,7} ranges
  • All features can be combined: ```php #=5 {2,4}

Syntax Examples

Syntax Result
```php Plain code block
```php # With line numbers
```php #=5 Line numbers starting at 5
```php {3,5-7} Highlight lines, no numbers
```php # {3,5-7} Line numbers + highlighting
```php #=5 {3,5-7} Numbers from 5 + highlighting

HTML Output

When line numbers or highlighting are enabled, the renderer:

  • Adds line-numbers class to <pre> when line numbers enabled
  • Adds data-start="N" attribute when start offset != 1
  • Adds has-highlighted-lines class when highlighting used
  • Wraps each line in <span class="line" data-line="N">
  • Adds highlighted class to highlighted line spans

Example output:

<pre class="line-numbers has-highlighted-lines" data-start="5"><code class="language-php"><span class="line" data-line="5">$foo = 1;</span>
<span class="line highlighted" data-line="6">$bar = 2;</span>
<span class="line" data-line="7">$baz = 3;</span>
</code></pre>

CSS can then style line numbers via counters and highlighted lines with background colors.

Adds VitePress-inspired syntax for code blocks:
- `php #` - show line numbers
- `php #=5` - line numbers starting at 5
- `php {2,4-6}` - highlight specific lines
- `php # {2,4}` - combine both features

HTML output includes:
- `line-numbers` class on pre element when enabled
- `data-start` attribute when start offset != 1
- `has-highlighted-lines` class when highlighting used
- Each line wrapped in span.line with data-line attribute
- `highlighted` class added to highlighted lines
@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

❌ Patch coverage is 87.50000% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.72%. Comparing base (9b26950) to head (0bdc767).

Files with missing lines Patch % Lines
src/Node/Block/CodeBlock.php 50.00% 6 Missing ⚠️
src/Renderer/HtmlRenderer.php 85.71% 6 Missing ⚠️
src/Parser/Block/FencedBlockParser.php 97.67% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master      #82      +/-   ##
============================================
- Coverage     93.85%   93.72%   -0.13%     
- Complexity     2115     2149      +34     
============================================
  Files            77       77              
  Lines          5675     5773      +98     
============================================
+ Hits           5326     5411      +85     
- Misses          349      362      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extra beyond standard/specs RFC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant