-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[RFC] Use css counter for line numbers #4743
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
incredible! btw you can display content before the .PlaygroundTheme__code>br+br {
display: block;
content: counter(line-number);
height: 20px;
}
.PlaygroundTheme__code>br+br:before {
color: #777;
content: counter(line-number);
user-select: none;
position: absolute;
left: 5px;
width: 50px;
} |
Hi @fantactuka , I too needed this fix. Since you closed this, Are you planning on any alternate fix for code block line numbers issue? |
@ibastawisi That doesn't work in Firefox and Safari, unfortunately. Also in Chrome the caret starts behaving funny around empty lines. If you move it with the left/right arrow keys, it needs two key presses instead of one. |
For me, I just needed this to style exported html without |
It's quite buggy as @thorn0 said, though I'm still using it on my project. But I plan to set |
Alternative approach for line numbers. Current implementation adds
data-gutter
attribute that includes line numbers that are rendered viacode_block:before
content. It has issues with line-wraps as data-gutter does not calculate amount of visible lines taken by one line of code. On top of it, it uses caching logic to throttle gutter recalculation and its value might become invalid.This approach uses css counters. Spans or line breaks that are preceded by a line break are line starters, so we could use those to count lines and style their
:before
to include counter content. It requires zero javascript and its only downside is it can't render line numbers for empty lines because br:before is not accepting much of styles: