code block line numbers

This commit is contained in:
Joshua Seigler 2025-07-10 23:50:28 -04:00
parent 2766453d75
commit 0226171b58
7 changed files with 159 additions and 99 deletions

View file

@ -7,8 +7,7 @@ pre[class*="language-"] {
word-break: normal;
word-wrap: normal;
font-size: 0.8rem;
line-height: 1.5em;
color: var(--c-text-dim);
line-height: 1.4;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
@ -20,16 +19,49 @@ pre[class*="language-"] {
:not(pre) > code[class*="language-"] {
background: var(--c-text-background-light);
white-space: normal;
border-radius: 0.2em;
border-radius: 0.2rem;
padding: 0.1em;
}
pre[class*="language-"] {
background: color-mix(in lch, var(--c-text-background-light) 20%, transparent);
overflow: auto;
> code {
white-space: pre-wrap;
word-break: break-all;
}
position: relative;
margin: 0.5em 0;
padding: 1.25em 1em;
padding: 0.5em 1em 0.5em calc(var(--lineNumWidth) + 0.25rem);
box-shadow: inset 0 0 6rem -2rem var(--c-highlight);
counter-reset: lineNumber;
--places: 1;
&:has(.highlight-line:nth-child(10)) { --places: 2 }
&:has(.highlight-line:nth-child(100)) { --places: 3 }
&:has(.highlight-line:nth-child(1000)) { --places: 4 }
--lineNumWidth: calc(1em + var(--places) * 1ch);
&::before {
content: '';
position: absolute;
height: 100%;
top: 0;
left: var(--lineNumWidth);
width: 3rem;
opacity: 0.125;
z-index: -1;
background: linear-gradient(to right, var(--c-highlight), transparent);
border-radius: 0.5em;
}
.highlight-line {
position: relative;
}
.highlight-line::before {
content: counter(lineNumber);
counter-increment: lineNumber;
position: absolute;
top: 0;
right: calc(100% + 0.5em);
color: var(--c-highlight);
word-break: normal;
}
}
p:has(+ pre[class*="language-"]) > code {
margin: 0;
@ -46,44 +78,47 @@ p:has(>code) + pre[class*="language-"] {
.token.id { font-weight: bold; }
.token.important { font-weight: bold; }
.language-css > code,
.language-sass > code,
.language-scss > code {
color: #fd9170;
@media screen {
pre[class*="language-"] { color: var(--c-text-dim); }
.language-css > code,
.language-sass > code,
.language-scss > code {
color: #fd9170;
}
.token.atrule { color: #c792ea; }
.token.attr-name { color: #ffcb6b; }
.token.attr-value { color: #a5e844; }
.token.attribute { color: #a5e844; }
.token.boolean { color: #c792ea; }
.token.builtin { color: #ffcb6b; }
.token.cdata { color: #80cbc4; }
.token.char { color: #80cbc4; }
.token.class { color: #ffcb6b; }
.token.class-name { color: #f2ff00; }
.token.comment { color: #616161; }
.token.constant { color: #c792ea; }
.token.deleted { color: #ff6666; }
.token.doctype { color: #616161; }
.token.entity { color: #ff6666; }
.token.function { color: #c792ea; }
.token.hexcode { color: #f2ff00; }
.token.id { color: #c792ea; }
.token.important { color: #c792ea; }
.token.inserted { color: #80cbc4; }
.token.keyword { color: #c792ea; }
.token.number { color: #fd9170; }
.token.operator { color: #89ddff; }
.token.prolog { color: #616161; }
.token.property { color: #80cbc4; }
.token.pseudo-class { color: #a5e844; }
.token.pseudo-element { color: #a5e844; }
.token.punctuation { color: #89ddff; }
.token.regex { color: #f2ff00; }
.token.selector { color: #ff6666; }
.token.string { color: #a5e844; }
.token.symbol { color: #c792ea; }
.token.tag { color: #ff6666; }
.token.unit { color: #fd9170; }
.token.url { color: #ff6666; }
.token.variable { color: #ff6666; }
}
.token.atrule { color: #c792ea; }
.token.attr-name { color: #ffcb6b; }
.token.attr-value { color: #a5e844; }
.token.attribute { color: #a5e844; }
.token.boolean { color: #c792ea; }
.token.builtin { color: #ffcb6b; }
.token.cdata { color: #80cbc4; }
.token.char { color: #80cbc4; }
.token.class { color: #ffcb6b; }
.token.class-name { color: #f2ff00; }
.token.comment { color: #616161; }
.token.constant { color: #c792ea; }
.token.deleted { color: #ff6666; }
.token.doctype { color: #616161; }
.token.entity { color: #ff6666; }
.token.function { color: #c792ea; }
.token.hexcode { color: #f2ff00; }
.token.id { color: #c792ea; }
.token.important { color: #c792ea; }
.token.inserted { color: #80cbc4; }
.token.keyword { color: #c792ea; }
.token.number { color: #fd9170; }
.token.operator { color: #89ddff; }
.token.prolog { color: #616161; }
.token.property { color: #80cbc4; }
.token.pseudo-class { color: #a5e844; }
.token.pseudo-element { color: #a5e844; }
.token.punctuation { color: #89ddff; }
.token.regex { color: #f2ff00; }
.token.selector { color: #ff6666; }
.token.string { color: #a5e844; }
.token.symbol { color: #c792ea; }
.token.tag { color: #ff6666; }
.token.unit { color: #fd9170; }
.token.url { color: #ff6666; }
.token.variable { color: #ff6666; }