Skip to content

Commit d1f5a56

Browse files
authored
Added codeblocks v1 support to new theme (#131)
1 parent 581caad commit d1f5a56

File tree

2 files changed

+133
-4
lines changed

2 files changed

+133
-4
lines changed

assets/css/v2/style.css

Lines changed: 119 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
--color-footer-text: #E2E2E2;
2121
--color-product-title: #8D8D8D;
2222
--color-table-divider: #CCCCCC;
23-
23+
--color-codeblock-code-with-comment: #00963926;
24+
2425
--sidebar-margin: 24px;
2526
--sidebar-line-box-side-length: 8px;
2627
--sidebar-line-box-top: 6px;
@@ -33,13 +34,20 @@
3334
--table-min-column-spacing-narrow: 1.5rem;
3435
--table-min-column-spacing-wide: 0.75rem;
3536
--table-header-bottom-spacing: 1rem;
36-
--table-line-extension: 1rem;
3737
--table-line-height: 1px;
3838
--text-content-width-iphone-13: 30rem;
3939
--text-content-width-mbp-14: 40rem;
4040
--text-content-width-mbp-16: 50rem;
4141
--text-content-width-4k-display: 60rem;
42+
--codeblock-comment-diff: 2rem;
43+
--codeblock-comment-space-between: 10px;
44+
--codeblock-horizontal-line-length: 2rem;
45+
--codeblock-horizontal-line-overflow: 0.25rem;
46+
--codeblock-border-thickness: 1px;
47+
--codeblock-code-section-padding-left: 1rem;
48+
--codeblock-line-box-side-length: 4px;
4249
--component-gap: 3.5rem;
50+
--overflow-gutter-extension: 1rem;
4351

4452
}
4553

@@ -667,8 +675,8 @@ table {
667675
position: absolute;
668676
border-bottom: var(--table-line-height) solid var(--color-table-divider);
669677
bottom: 0;
670-
left: calc(-1 * var(--table-line-extension));
671-
width: calc(100% + (2 * var(--table-line-extension)));
678+
left: calc(-1 * var(--overflow-gutter-extension));
679+
width: calc(100% + (2 * var(--overflow-gutter-extension)));
672680
}
673681
}
674682

@@ -736,16 +744,123 @@ blockquote p:last-child {
736744
margin: 0 auto;
737745
}
738746

747+
/* Codeblocks */
748+
.highlight {
749+
grid-column: 1 / -1 !important;
750+
position: relative;
751+
margin-left: calc(var(--overflow-gutter-extension) / -2);
752+
width: calc(100% + var(--overflow-gutter-extension));
753+
}
754+
739755
code {
740756
font-weight: light;
741757
font-family: 'JetBrains Mono', monospace;
758+
display: flex;
759+
flex-direction: column;
742760
}
743761

744762
pre.chroma {
745763
overflow-x: auto;
746764
box-sizing: border-box;
747765
}
748766

767+
code .line {
768+
position: relative;
769+
display: grid;
770+
grid-template-columns: 1fr 1fr;
771+
grid-template-areas: " code "
772+
" comment ";
773+
}
774+
775+
code .line:has(.comment) .code {
776+
display: inline-block;
777+
height: fit-content;
778+
white-space: pre-wrap;
779+
width: 100%;
780+
background-color: var(--color-codeblock-code-with-comment);
781+
margin: var(--codeblock-comment-space-between) 0;
782+
position: relative;
783+
grid-column: 1 / -1;
784+
}
785+
786+
code .line:not(:has(.comment)) .code {
787+
grid-column: 1 / -1;
788+
grid-row: 1;
789+
}
790+
791+
code:not(:has(.comment)) .code {
792+
/* For codeblocks without comments */
793+
grid-column: 1 / -1 !important;
794+
grid-row: 1;
795+
}
796+
797+
code .code {
798+
padding-left: var(--codeblock-code-section-padding-left);
799+
grid-area: code;
800+
}
801+
802+
code .comment {
803+
display: inline-block;
804+
white-space: normal;
805+
margin: var(--codeblock-comment-space-between) 0;
806+
width: calc(100vw - (var(--codeblock-comment-diff) * 2));
807+
border: black var(--codeblock-border-thickness) solid;
808+
box-shadow: 3px 3px 0px var(--color-shadow);
809+
padding: 8px;
810+
grid-column: 1 / -1;
811+
}
812+
813+
code .line:has(.comment) .code::before {
814+
/* Vertical Lines */
815+
content: '';
816+
position: absolute;
817+
border-left: black var(--codeblock-border-thickness) solid;
818+
left: calc(var(--codeblock-horizontal-line-overflow) + 1px);
819+
top: 10px;
820+
height: calc(100% + 0.7rem);
821+
}
822+
823+
code .line:has(.comment) .code::after {
824+
/* Block */
825+
content: '';
826+
background-color: black;
827+
position: absolute;
828+
height: var(--codeblock-line-box-side-length);
829+
width: var(--codeblock-line-box-side-length);
830+
top: calc(10px - (var(--codeblock-border-thickness) * 1.5));
831+
left: var(--codeblock-horizontal-line-overflow);
832+
}
833+
834+
@media (min-width: 768px) { /* Tablet */
835+
code .line:has(.comment) .code {
836+
grid-column: 2 / -1;
837+
}
838+
839+
code .comment {
840+
grid-column: 1;
841+
width: calc(100% - (var(--codeblock-comment-diff)));
842+
}
843+
844+
code .line:not(:has(.comment)) .code {
845+
grid-column: 2 / -1;
846+
}
847+
848+
code .line {
849+
/* Readjust the areas to be more responsive */
850+
grid-template-columns: 40% 60%;
851+
grid-template-areas: "comment code";
852+
}
853+
854+
code .line:has(.comment) .code::before {
855+
/* Horizontal Lines */
856+
border-left: none;
857+
border-top: black var(--codeblock-border-thickness) solid;
858+
left: calc(var(--codeblock-comment-diff) * -1);
859+
width: calc(var(--codeblock-horizontal-line-length) + var(--codeblock-horizontal-line-overflow));
860+
}
861+
}
862+
863+
/* Logo */
749864
.f5-logo-footer {
750865
height: 32px;
751866
width: 32px;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{ $code := .Inner | safeHTML }}
2+
{{ $lines := split $code "\n" }}
3+
<div class="highlight">
4+
<pre class="chroma" tabindex="0">
5+
<code class="language-{{ .Type }}">
6+
{{ range $lines }}
7+
<span class="line">{{ $line := . }}{{ $parts := split $line "#" }}<span class="code">{{ index $parts 0 | safeHTML }}
8+
</span>{{ $commentPart := "" }}{{ if gt (len $parts) 1 }}<span class="comment">{{ index $parts 1 | safeHTML }}</span>{{ end }}</span>
9+
{{ end }}
10+
</code>
11+
</pre>
12+
</div>
13+
14+
<!-- ABSOLUTELY DO NOT CHANGE THIS ORDER -->

0 commit comments

Comments
 (0)