fix(code-block): size line-number gutter to the widest line number - #483
Open
drPod wants to merge 1 commit into
Open
fix(code-block): size line-number gutter to the widest line number#483drPod wants to merge 1 commit into
drPod wants to merge 1 commit into
Conversation
The line number was a fixed-width inline-block (w-8, 32px) followed by a 16px margin. A 14px mono digit is ~8.4px, so three digits fit but longer numbers spill past the box into the gap: at four digits the gap shrinks to ~14px, at five to ~6px, and at six the number overlaps the code. Make <code> a two-column grid with line numbers on, render each line as display: contents, and let the ::before number and the content span be grid items. The number column now sizes to the widest line number, with min-w-12 (48px, incl. 16px padding) keeping blocks up to 999 lines pixel-identical to before.
Contributor
|
@drPod is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The line number is a fixed-width inline-block (
before:w-8, 32px) with a 16px margin (before:mr-4). At 14px a mono digit is ~8.4px, so three digits fit and anything longer spills past the box into the gap: at 4 digits the gap shrinks to ~14px, at 5 to ~6px, and at 6 the number overlaps the code.With
showLineNumbers,<code>is now a two-column grid and each line isdisplay: contents, so the::beforenumber and the line's content span are grid items and the number column sizes to the widest line number.before:min-w-12(48px incl. padding) keeps blocks up to 999 lines pixel-identical to today; only wider numbers change. Line numbers stay::before, so select/copy still returns only the code.Before / After
Related issues: none.
pnpm checkandpnpm testpass. Includes a patch changeset.