Skip to content

feat: scroll to highlighted lines in code blocks #201

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 14 commits into from
Mar 21, 2025

Conversation

m-ods
Copy link
Contributor

@m-ods m-ods commented Mar 19, 2025

This PR adds functionality to automatically scroll highlighted lines into view within code blocks. When a code block contains highlighted lines (e.g., highlight={19}), the script will:

  • Detect code blocks with highlighted lines
  • Calculate the optimal scroll position to center the highlighted line
  • Automatically scroll the code block's viewport to show the highlighted line
  • Maintain this behavior during page loads and client-side navigation

This improves the user experience by ensuring highlighted lines are immediately visible without requiring manual scrolling, particularly useful in documentation where specific lines are referenced.

Before:
image

After:
image

Copy link

Copy link

Copy link

Copy link

Copy link

@m-ods m-ods requested a review from a-dinoto March 21, 2025 07:23
Copy link

Copy link

Copy link
Contributor

@a-dinoto a-dinoto left a comment

Choose a reason for hiding this comment

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

Every snippet that contains highlighting centers the highlighted section by default. Nice job! There were a few larger code snippets that were missing highlighting, which I have added.

Copy link

@m-ods m-ods merged commit e685a32 into main Mar 21, 2025
2 checks passed
@m-ods m-ods deleted the mart/scroll-highlighted-code branch March 21, 2025 17:57
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.

None yet

2 participants