Skip to content

Conversation

@Sdju
Copy link
Contributor

@Sdju Sdju commented Oct 29, 2025

Add line numbers for code blocks in Slidev VSCode extension

Motivation

I have many code blocks in my presentations. And I often need to know line numbers (e.g., for line highlighting {1|7-9...} ). It would therefore be useful to see line numbers directly in the editor.

Description

This PR adds an optional feature to display line numbers for code blocks in the Slidev VSCode extension, making it easier to reference specific lines when working with code in presentations.

Screenshots

image image

Changes

1. Line numbers decoration for code blocks

  • Added automatic line numbering for code blocks (triple backticks ```)
  • Ignores special blocks like magic-move (4+ backticks)
  • Added slidev.annotations-line-numbers setting (default: true)

Known issues

  1. Doesn't respect the startLine option
  2. Shares the same triggers for creating annotations — looks odd until the document is saved
    image [Fixed]

@netlify
Copy link

netlify bot commented Oct 29, 2025

Deploy Preview for slidev ready!

Name Link
🔨 Latest commit 4ee5d32
🔍 Latest deploy log https://app.netlify.com/projects/slidev/deploys/691af427266fb700089535b5
😎 Deploy Preview https://deploy-preview-2320--slidev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 29, 2025

Open in StackBlitz

@slidev/client

npm i https://pkg.pr.new/slidevjs/slidev/@slidev/client@2320

create-slidev

npm i https://pkg.pr.new/slidevjs/slidev/create-slidev@2320

create-slidev-theme

npm i https://pkg.pr.new/slidevjs/slidev/create-slidev-theme@2320

@slidev/parser

npm i https://pkg.pr.new/slidevjs/slidev/@slidev/parser@2320

@slidev/cli

npm i https://pkg.pr.new/slidevjs/slidev/@slidev/cli@2320

@slidev/types

npm i https://pkg.pr.new/slidevjs/slidev/@slidev/types@2320

commit: 387fdbd

@Sdju Sdju changed the title feat: show line numbers in markdown blocks [DRAFT] feat: show line numbers in markdown blocks Oct 29, 2025
@antfu antfu requested a review from kermanx October 30, 2025 05:39
@antfu
Copy link
Member

antfu commented Oct 30, 2025

Love the idea!

Copy link
Member

@kermanx kermanx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The lint error seems to require manual update. About the odd behavior when the document is not saved yet, I wasn't noticing this because I always have autoSave on🥲. Maybe it should be fixed somehow later.

@Sdju
Copy link
Contributor Author

Sdju commented Oct 30, 2025

The lint error seems to require manual update.

Fixed

zede and others added 3 commits October 30, 2025 17:30
- Fix incorrect output until document is saved
- Fix wrong line numbers for rows with 2+ digits
- Fix rendering of lines containing only whitespace
@Sdju Sdju changed the title [DRAFT] feat: show line numbers in markdown blocks feat: show line numbers in markdown blocks Nov 17, 2025
Copy link
Member

@kermanx kermanx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. However, we aren't able to release it before #2207, which is still blocked by upstream.

@antfu antfu merged commit 917bca2 into slidevjs:main Nov 18, 2025
18 of 19 checks passed
@ragavkumarv
Copy link

Very useful and pragmatic feature. Thanks for doing this ❤️.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants