Skip to content

Commit 5961240

Browse files
committed
Improve styling of multiline code blocks
1 parent 265e53a commit 5961240

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

styles/content.scss

+9
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@
5252
color: $code;
5353
font-family: 'Roboto Mono', monospace;
5454
font-weight: 400;
55+
56+
.highlighted {
57+
color: $code-light;
58+
background:$code-light-background;
59+
border-radius: 2px;
60+
padding: 1rem;
61+
box-shadow: inset 0px 0px 2rem rgba(0, 0, 0, 0.3), 0px 0.4rem 1rem rgba(0, 0, 0, 0.2);
62+
overflow-x: auto;
63+
}
5564
}
5665

5766
.content img {

styles/variables.scss

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ $light-background: hsl(0, 100%, 99%);
22
$light-foreground: hsl(0, 79%, 15%);
33
$light-foreground-2: hsl(99, 42%, 15%);
44
$code: hsl(22, 98%, 18%);
5+
$code-light: hsl(22, 70%, 90%);
6+
$code-light-background: hsl(22, 35%, 22%);
57

68
$dark-background: hsl(100, 47%, 25%);
79
$dark-foreground: hsl(200, 45%, 98%);

util/renderMarkdown.mjs

+11-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@ import hljs from 'highlight.js'
55
const markdown = new remarkable({
66
linkTarget: '_blank',
77
highlight: function (str, lang) {
8+
let result = ''
9+
810
if (lang && hljs.getLanguage(lang)) {
911
try {
10-
return hljs.highlight(lang, str).value;
12+
result = hljs.highlight(lang, str).value;
13+
} catch (err) {}
14+
}
15+
else {
16+
try {
17+
result = hljs.highlightAuto(str).value;
1118
} catch (err) {}
1219
}
1320

14-
try {
15-
return hljs.highlightAuto(str).value;
16-
} catch (err) {}
21+
if (result) {
22+
return `<div class="highlighted">${result}</div>`
23+
}
1724

1825
return ''; // use external default escaping
1926
}

0 commit comments

Comments
 (0)