Skip to content

Commit 6d99f5c

Browse files
committed
feat(ui): improve code snippet design
1 parent 0c80552 commit 6d99f5c

File tree

4 files changed

+46
-39
lines changed

4 files changed

+46
-39
lines changed

_includes/refactor-content.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@
219219

220220
{% if _left contains 'file="' %}
221221
{% assign _label_text = _left | split: 'file="' | last | split: '"' | first %}
222-
{% assign _label_icon = 'far fa-file-code' %}
222+
{% assign _label_icon = 'far fa-file-code fa-fw' %}
223223
{% else %}
224224
{% assign _lang = _left | split: 'language-' | last | split: ' ' | first %}
225225
{% capture _label_text %}{% include language-alias.html language=_lang %}{% endcapture %}
226-
{% assign _label_icon = 'fas fa-code small' %}
226+
{% assign _label_icon = 'fas fa-code fa-fw small' %}
227227
{% endif %}
228228

229229
{% capture _label %}

_sass/addon/syntax.scss

+42-37
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ html {
3232
/* -- code snippets -- */
3333

3434
%code-snippet-bg {
35-
background: var(--highlight-bg-color);
35+
background-color: var(--highlight-bg-color);
3636
}
3737

3838
%code-snippet-padding {
@@ -41,9 +41,6 @@ html {
4141
}
4242

4343
.highlighter-rouge {
44-
@extend %code-snippet-bg;
45-
@extend %rounded;
46-
4744
color: var(--highlighter-rouge-color);
4845
margin-top: 0.5rem;
4946
margin-bottom: 1.2em; /* Override BS Inline-code style */
@@ -140,13 +137,25 @@ td.rouge-code {
140137
}
141138
}
142139

140+
div[class^='language-'] {
141+
@extend %rounded;
142+
@extend %code-snippet-bg;
143+
144+
box-shadow: var(--language-border-color) 0 0 0 1px;
145+
146+
.post-content > & {
147+
@include ml-mr(-1.25rem);
148+
149+
border-radius: 0;
150+
}
151+
}
152+
143153
/* Hide line numbers for default, console, and terminal code snippets */
144154
div {
145-
&[class^='highlighter-rouge'],
146155
&.nolineno,
147-
&.language-plaintext.highlighter-rouge,
148-
&.language-console.highlighter-rouge,
149-
&.language-terminal.highlighter-rouge {
156+
&.language-plaintext,
157+
&.language-console,
158+
&.language-terminal {
150159
pre.lineno {
151160
display: none;
152161
}
@@ -166,28 +175,15 @@ div {
166175
justify-content: space-between;
167176
align-items: center;
168177
height: $code-header-height;
169-
170-
&::before {
171-
$dot-size: 0.75rem;
172-
$dot-margin: 0.5rem;
173-
174-
content: '';
175-
display: inline-block;
176-
margin-left: 1rem;
177-
width: $dot-size;
178-
height: $dot-size;
179-
border-radius: 50%;
180-
background-color: var(--code-header-muted-color);
181-
box-shadow: ($dot-size + $dot-margin) 0 0 var(--code-header-muted-color),
182-
($dot-size + $dot-margin) * 2 0 0 var(--code-header-muted-color);
183-
}
178+
margin-left: 1rem;
179+
margin-right: 0.25rem;
184180

185181
/* the label block */
186182
span {
187183
/* label icon */
188184
i {
189185
font-size: 1rem;
190-
margin-right: 0.4rem;
186+
margin-right: 0.5rem;
191187
color: var(--code-header-icon-color);
192188

193189
&.small {
@@ -248,21 +244,30 @@ div {
248244
}
249245
}
250246

251-
@media all and (max-width: 576px) {
252-
.post-content {
253-
> div[class^='language-'] {
254-
@include ml-mr(-1.25rem);
255-
256-
border-radius: 0;
247+
@media all and (min-width: 576px) {
248+
div[class^='language-'] {
249+
.post-content > & {
250+
@include ml-mr(0);
257251

258-
.highlight {
259-
padding-left: 0.25rem;
260-
}
252+
border-radius: $base-radius;
253+
}
261254

262-
.code-header {
263-
border-radius: 0;
264-
padding-left: 0.4rem;
265-
padding-right: 0.5rem;
255+
.code-header {
256+
@include ml-mr(0);
257+
258+
&::before {
259+
$dot-size: 0.75rem;
260+
$dot-margin: 0.5rem;
261+
262+
content: '';
263+
display: inline-block;
264+
margin-left: 1rem;
265+
width: $dot-size;
266+
height: $dot-size;
267+
border-radius: 50%;
268+
background-color: var(--code-header-muted-color);
269+
box-shadow: ($dot-size + $dot-margin) 0 0 var(--code-header-muted-color),
270+
($dot-size + $dot-margin) * 2 0 0 var(--code-header-muted-color);
266271
}
267272
}
268273
}

_sass/colors/dark-syntax.scss

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
@mixin dark-syntax {
6+
--language-border-color: rgba(84, 83, 83, 0.27);
67
--highlight-bg-color: #252525;
78
--highlighter-rouge-color: #de6b18;
89
--highlight-lineno-color: #6c6c6d;

_sass/colors/light-syntax.scss

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
.highlight .il { color: #009999; } /* Literal.Number.Integer.Long */
6868

6969
/* --- custom light colors --- */
70+
--language-border-color: rgba(172, 169, 169, 0.2);
7071
--highlight-bg-color: #f7f7f7;
7172
--highlighter-rouge-color: #3f596f;
7273
--highlight-lineno-color: #c2c6cc;

0 commit comments

Comments
 (0)