redesign code blocks

This commit is contained in:
panr
2025-03-03 11:10:04 +01:00
parent 0d9cf692a9
commit 361a37916b
3 changed files with 56 additions and 19 deletions

View File

@ -1,14 +1,15 @@
code { :root {
color: var(--accent); --code-border: color-mix(in srgb, var(--foreground) 10%, transparent);
border: 1px solid color-mix(in srgb, var(--foreground) 10%, transparent)
} }
pre:not(.chroma), pre:not(.chroma) {
.highlight {
margin: 20px 0; margin: 20px 0;
padding: 10px;
} }
pre.chroma { pre.chroma {
margin: 0;
padding: 10px 0;
color: var(--foreground); color: var(--foreground);
} }
@ -17,10 +18,45 @@ pre code {
border: none; border: none;
} }
code {
color: var(--accent);
}
.highlight {
position: relative;
padding-top: 30px;
margin: 20px 0;
border: 1px solid var(--code-border);
}
.highlight pre {
border: none;
}
.chroma code[data-lang]:before {
content: attr(data-lang);
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: auto;
height: 30px;
display: flex;
align-items: center;
background: color-mix(in srgb, var(--foreground) 5%, transparent);
border-bottom: 1px solid var(--code-border);
color: var(--comment);
text-transform:uppercase;
font-size: .8em;
padding: 0 10px;
line-height: 1;
}
.collapsable-code { .collapsable-code {
position: relative; position: relative;
width: 100%; width: 100%;
margin: 40px 0; margin: 20px 0;
border: 1px solid var(--accent);
.highlight { .highlight {
margin: 0; margin: 0;
@ -28,9 +64,12 @@ pre code {
} }
.collapsable-code__title { .collapsable-code__title {
display: inline-flex;
align-items: center;
flex: 1; flex: 1;
color: var(--accent); color: var(--accent);
padding: 3px 10px; padding: 3px 10px;
font-size: .9em;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
@ -45,7 +84,6 @@ pre code {
} }
.collapsable-code summary { .collapsable-code summary {
border-bottom: 1px solid var(--accent);
color: var(--accent); color: var(--accent);
padding: 0 10px; padding: 0 10px;
cursor: pointer; cursor: pointer;
@ -56,12 +94,12 @@ pre code {
} }
.collapsable-code summary::marker { .collapsable-code summary::marker {
content: "+"; /* content: "+"; */
font-weight: bold; font-weight: bold;
} }
.collapsable-code[open] summary::marker { .collapsable-code[open] summary::marker {
content: "-"; /* content: "-"; */
} }

View File

@ -5,20 +5,19 @@
} }
/* Background */ .bg { } /* Background */ .bg { }
/* PreWrapper */ pre.chroma { position: relative; padding:15px 0; } /* PreWrapper */ .chroma { overflow:auto; }
/* Custom:CodeInfo */ .chroma code[data-lang]:before { content: attr(data-lang);position:absolute;top:0;right:0;color:var(--comment);text-transform:uppercase;font-size:.8em;padding:.5em;line-height:1;}
/* Other */ .chroma .x { } /* Other */ .chroma .x { }
/* Error */ .chroma .err { } /* Error */ .chroma .err { }
/* CodeLine */ .chroma .cl { } /* CodeLine */ .chroma .cl { }
/* LineLink */ .chroma .lnlinks { outline:none;text-decoration:none;color:inherit } /* LineLink */ .chroma .lnlinks { outline:none;text-decoration:none;color:inherit }
/* Custom */ .chroma .lntd:first-child { width:auto;vertical-align:top;padding:0;margin:0;border:0; }
/* LineTableTD */ .chroma .lntd { width:100%;vertical-align:top;padding:0;margin:0;border:0; } /* LineTableTD */ .chroma .lntd { width:100%;vertical-align:top;padding:0;margin:0;border:0; }
/* LineTableTDNumbers */ .chroma .lntd:first-child { width: auto; }
/* Custom */ .chroma .lntd code { display:grid; } /* Custom */ .chroma .lntd code { display:grid; }
/* LineTable */ .chroma .lntable { border-spacing:0;padding:0;margin:0;border:0; } /* LineTable */ .chroma .lntable { width:100%;border-spacing:0;padding:0;margin:0;border:0; }
/* LineHighlight */ .chroma .hl { background-color:color-mix(in srgb, var(--foreground) 5%, transparent) !important} /* LineHighlight */ .chroma .hl { background-color:color-mix(in srgb, var(--foreground) 5%, transparent) !important}
/* LineNumbersTable */ .chroma .lnt { color:var(--comment);white-space:pre;-webkit-user-select:none;user-select:none;padding:0 15px; } /* LineNumbersTable */ .chroma .lnt { color:var(--comment);white-space:pre;-webkit-user-select:none;user-select:none;padding:0 10px; }
/* LineNumbers */ .chroma .ln { color:var(--comment);white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.8em;padding:0 0.4em 0 0; } /* LineNumbers */ .chroma .ln { color:var(--comment);white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.8em;padding:0 0.4em 0 0; }
/* Line */ .chroma .line { display:flex;padding:0 15px; } /* Line */ .chroma .line { display:flex;padding:0 10px; }
/* Keyword */ .chroma .k { color:var(--second-tone) } /* Keyword */ .chroma .k { color:var(--second-tone) }
/* KeywordConstant */ .chroma .kc { color:var(--second-tone) } /* KeywordConstant */ .chroma .kc { color:var(--second-tone) }
/* KeywordDeclaration */ .chroma .kd { color:var(--second-tone) } /* KeywordDeclaration */ .chroma .kd { color:var(--second-tone) }

View File

@ -1,15 +1,15 @@
{{ $id := delimit (shuffle (seq 1 9)) "" }} {{ $id := delimit (shuffle (seq 1 9)) "" }}
{{ $open := .Get "open" }} {{ $open := .Get "open" }}
{{ $lang := .Get "language" }} {{ $lang := .Get "language" }}
{{ $opts := .Get "opts" }}
{{- if $lang -}} {{- if $lang -}}
<details class="collapsable-code" title="Click to interact" {{ if eq $open "true" -}} open {{- end }}> <details class="collapsable-code" {{ if eq $open "true" -}} open {{- end }}>
<summary> <summary title="Click to interact">
<span class="collapsable-code__language">{{ $lang }}</span>
{{- if .Get "title" }}<span class="collapsable-code__title">{{ .Get "title" | markdownify }}</span>{{ end -}} {{- if .Get "title" }}<span class="collapsable-code__title">{{ .Get "title" | markdownify }}</span>{{ end -}}
</summary> </summary>
{{ $trInner := trim .Inner "\n" }} {{ $trInner := trim .Inner "\n" }}
{{- transform.Highlight $trInner ($lang) -}} {{- transform.Highlight $trInner $lang $opts -}}
</details> </details>
{{ else }} {{ else }}
{{ errorf "If you want to use the \"collapsable code\" shortcode, you need to pass a mandatory \"language\" param. The issue occured in %q (%q)" .Page.File .Page.Permalink }} {{ errorf "If you want to use the \"collapsable code\" shortcode, you need to pass a mandatory \"language\" param. The issue occured in %q (%q)" .Page.File .Page.Permalink }}