Skip to content

Commit 80d3921

Browse files
committed
feat: Added fancy codeblocks
1 parent f9a15f3 commit 80d3921

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

assets/css/v2/style.css

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,61 @@ blockquote p:last-child {
973973
}
974974

975975
/* Codeblocks */
976+
.highlight {
977+
grid-column: 1 / -1 !important;
978+
width: 100%;
979+
position: relative;
980+
z-index: -1;
981+
display: grid;
982+
grid-template-columns: 40% 60%;
983+
984+
pre.chroma {
985+
grid-column: 1 / -1;
986+
}
987+
988+
code .line {
989+
display: grid;
990+
grid-template-columns: 40% 60%;
991+
grid-template-areas: "comment code";
992+
position: relative;
993+
994+
.cl {
995+
grid-column: 2 / -1;
996+
grid-area: code;
997+
}
998+
999+
.c1:not(:empty) {
1000+
position: relative;
1001+
display: inline-block;
1002+
white-space: normal;
1003+
margin-bottom: var(--codeblock-comment-space-between);
1004+
width: calc(100% - (var(--codeblock-comment-diff) * 2));
1005+
border: black var(--codeblock-border-thickness) solid;
1006+
box-shadow: 3px 3px 0px var(--color-shadow);
1007+
padding: 8px;
1008+
grid-column: 1;
1009+
grid-area: comment;
1010+
}
1011+
1012+
&:has(.c1:not(:empty)) .cl {
1013+
height: fit-content;
1014+
margin-bottom: var(--codeblock-comment-space-between);
1015+
background-color: var(--color-codeblock-code-with-comment);
1016+
}
1017+
1018+
&:has(.c1) .cl::before {
1019+
content: "";
1020+
border-left: none;
1021+
border-top: black var(--codeblock-border-thickness) solid;
1022+
left: calc(var(--codeblock-comment-diff) * -1);
1023+
width: calc(
1024+
var(--codeblock-horizontal-line-length) +
1025+
var(--codeblock-horizontal-line-overflow)
1026+
);
1027+
}
1028+
}
1029+
}
1030+
9761031
.highlight-mf {
9771032
grid-column: 1 / -1 !important;
9781033
position: relative;
@@ -1005,7 +1060,7 @@ blockquote p:last-child {
10051060
" comment ";
10061061
}
10071062

1008-
code .line:has(.comment) .code {
1063+
code .line:has(.comment) .code.c1 {
10091064
display: inline-block;
10101065
height: fit-content;
10111066
white-space: pre-wrap;

assets/js/codeblock-v2.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
document.addEventListener('DOMContentLoaded', () => {
2+
const codeblockLines = document.querySelectorAll('span.c1');
3+
codeblockLines.forEach((val) => {
4+
const parent = val.parentNode;
5+
parent.parentNode.insertBefore(val, parent.nextSibling);
6+
});
7+
});

layouts/partials/scripts.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@
6060

6161
{{ end }}
6262

63-
63+
<!-- Load Codeblock javascript -->
64+
{{ $jsCodeblockV2 := resources.Get "js/codeblock-v2.js" | minify | fingerprint "sha512" }}
65+
<script src="{{ $jsCodeblockV2.RelPermalink }}" type="text/javascript" integrity="{{ $jsCodeblockV2.Data.Integrity }}"></script>
6466

6567
<!-- Load Sidebar javascript -->
6668
{{ $jsSidebar := resources.Get "js/sidebar.js" | minify | fingerprint "sha512" }}

0 commit comments

Comments
 (0)