Skip to content

Added fancy codeblocks #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion assets/css/v2/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,61 @@ blockquote p:last-child {
}

/* Codeblocks */
.highlight {
grid-column: 1 / -1 !important;
width: 100%;
position: relative;
z-index: -1;
display: grid;
grid-template-columns: 40% 60%;

pre.chroma {
grid-column: 1 / -1;
}

code .line {
display: grid;
grid-template-columns: 40% 60%;
grid-template-areas: "comment code";
position: relative;

.cl {
grid-column: 2 / -1;
grid-area: code;
}

.c1:not(:empty) {
position: relative;
display: inline-block;
white-space: normal;
margin-bottom: var(--codeblock-comment-space-between);
width: calc(100% - (var(--codeblock-comment-diff) * 2));
border: black var(--codeblock-border-thickness) solid;
box-shadow: 3px 3px 0px var(--color-shadow);
padding: 8px;
grid-column: 1;
grid-area: comment;
}

&:has(.c1:not(:empty)) .cl {
height: fit-content;
margin-bottom: var(--codeblock-comment-space-between);
background-color: var(--color-codeblock-code-with-comment);
}

&:has(.c1) .cl::before {
content: "";
border-left: none;
border-top: black var(--codeblock-border-thickness) solid;
left: calc(var(--codeblock-comment-diff) * -1);
width: calc(
var(--codeblock-horizontal-line-length) +
var(--codeblock-horizontal-line-overflow)
);
}
}
}

.highlight-mf {
grid-column: 1 / -1 !important;
position: relative;
Expand Down Expand Up @@ -1005,7 +1060,7 @@ blockquote p:last-child {
" comment ";
}

code .line:has(.comment) .code {
code .line:has(.comment) .code.c1 {
display: inline-block;
height: fit-content;
white-space: pre-wrap;
Expand Down
7 changes: 7 additions & 0 deletions assets/js/codeblock-v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
document.addEventListener('DOMContentLoaded', () => {
const codeblockLines = document.querySelectorAll('span.c1');
codeblockLines.forEach((val) => {
const parent = val.parentNode;
parent.parentNode.insertBefore(val, parent.nextSibling);
});
});
4 changes: 3 additions & 1 deletion layouts/partials/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@

{{ end }}


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

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