From 78778dad0867773cd048bb73591e4734186d6d6f Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Sun, 17 May 2026 23:43:36 +0800 Subject: [PATCH] fix(code): fix line number styling for better visibility --- assets/scss/pages/single/_code.scss | 14 ++++++++++++-- layouts/_partials/plugin/code-block-wrapper.html | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/assets/scss/pages/single/_code.scss b/assets/scss/pages/single/_code.scss index 9b35481f..5065b567 100644 --- a/assets/scss/pages/single/_code.scss +++ b/assets/scss/pages/single/_code.scss @@ -135,11 +135,20 @@ } } + // line numbers (lineNumbersInTable=true) + .lnt { + display: block; + width: calc(#{fi-var(line-digit)} * 1ch); + min-width: 0.75rem; + text-align: right; + } // line numbers (lineNumbersInTable=false) .ln { - padding-right: 0.75rem; display: inline-block; + width: calc(#{fi-var(line-digit)} * 1ch); + min-width: 0.75rem; text-align: right; + padding-right: 0.75rem; position: sticky; left: 0; } @@ -474,7 +483,8 @@ content: counter(codeNos); white-space: nowrap; text-align: right; - min-width: calc(#{fi-var(line-digit)} * 1ch); + width: calc(#{fi-var(line-digit)} * 1ch); + min-width: 0.75rem; padding-inline: 0.75rem; flex-shrink: 0; color: fi-var(global-font-secondary-color); diff --git a/layouts/_partials/plugin/code-block-wrapper.html b/layouts/_partials/plugin/code-block-wrapper.html index ef3c2586..e34c74c3 100644 --- a/layouts/_partials/plugin/code-block-wrapper.html +++ b/layouts/_partials/plugin/code-block-wrapper.html @@ -19,7 +19,7 @@ {{- $lines := cond .Inner (len (split .Inner "\n")) 0 -}} {{- $maxShownLines := $config.maxshownlines -}} {{- $lineNoStart := cond (ne .Options.linenostart nil) .Options.linenostart 1 -}} - {{- $lineNosDigit := strings.RuneCount (add $lines $lineNoStart) -}} + {{- $lineNosDigit := strings.RuneCount (sub (add $lines $lineNoStart) 1) -}} {{- $class := "highlight" -}} {{- with $config.class -}}{{ $class = add $class " " . }}{{- end -}} {{- $targetClass := add "code-block " $class -}}