code block line numbers
This commit is contained in:
parent
2766453d75
commit
13e3e1a2da
5 changed files with 56 additions and 47 deletions
|
@ -7,7 +7,7 @@ pre[class*="language-"] {
|
|||
word-break: normal;
|
||||
word-wrap: normal;
|
||||
font-size: 0.8rem;
|
||||
line-height: 1.5em;
|
||||
line-height: 1.4;
|
||||
color: var(--c-text-dim);
|
||||
-moz-tab-size: 4;
|
||||
-o-tab-size: 4;
|
||||
|
@ -20,7 +20,7 @@ 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-"] {
|
||||
|
@ -28,8 +28,37 @@ pre[class*="language-"] {
|
|||
overflow: auto;
|
||||
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);
|
||||
}
|
||||
}
|
||||
p:has(+ pre[class*="language-"]) > code {
|
||||
margin: 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue