Skip to content
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

Extra Line Rendered with Line-Based Magic Comments in Code Highlighting #915

Closed
3 of 5 tasks
tszhong0411 opened this issue Feb 1, 2025 · 5 comments
Closed
3 of 5 tasks

Comments

@tszhong0411
Copy link

tszhong0411 commented Feb 1, 2025

Validations

Describe the bug

When using magic comments for code highlighting, I noticed an extra line rendered when the comment is on its line, compared to when it is inline. This only happens on the first line.

Example 1: Inline Comment (No Extra Line)

console.log('Not highlighted')
console.log('Highlighted') // [!code highlight]
console.log('Not highlighted')

This renders correctly without any extra lines.

Example 2: Line-Based Comment (Extra Line Rendered)

// [!code highlight:3]
console.log('Highlighted')
console.log('Highlighted')
console.log('Not highlighted')

In this case, an extra line is rendered above the highlighted block.

Screenshot

transformerNotationHighlight

Image

transformerNotationWordHighlight

Image

transformerNotationFocus

Image

Expected Behavior

Both inline and line-based magic comments should render the code block without introducing extra lines.

Actual Behavior

Line-based magic comments introduce an extra line above the highlighted block.

Additional Notes

I am unsure if this is expected behavior or a bug and if there is an existing issue that points to this behavior.

Reproduction

https://shiki.style/packages/transformers#transformernotationhighlight

Contributes

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests
@ole
Copy link

ole commented Feb 17, 2025

I agree. I find it distracting that a transformer-highlight comment (when placed on its own line) leaves a blank line in the output.

@ole
Copy link

ole commented Feb 18, 2025

@antfu Thanks a lot for the fix, much appreciated!

@sheremet-va
Copy link

@antfu
Copy link
Member

antfu commented Feb 18, 2025

@sheremet-va You might want to upgrade vitepress to v2.0.0-alpha.x and add versions resolutions

@sheremet-va
Copy link

You might want to upgrade vitepress to v2.0.0-alpha.x and add versions resolutions

Does it mean this fix doesn't work in vitespress@stable?

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

No branches or pull requests

4 participants