Skip to content

Commit 242fcc1

Browse files
authored
fix: make code block look prettier (#146)
1 parent 07337a9 commit 242fcc1

File tree

3 files changed

+55
-30
lines changed

3 files changed

+55
-30
lines changed

src/client/theme-default/styles/code.css

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ code {
22
margin: 0;
33
border-radius: 3px;
44
padding: .25rem .5rem;
5-
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace;
6-
font-size: 14px;
5+
font-family: var(--code-font-family);
6+
font-size: var(--code-font-size);
77
color: var(--c-text-light);
8-
background-color: rgba(27, 31, 35, .05);
8+
background-color: var(--code-inline-bg-color);
99
}
1010

1111
code .token.deleted {
@@ -18,33 +18,34 @@ code .token.inserted {
1818

1919
div[class*='language-'] {
2020
position: relative;
21-
margin: 14px 0;
22-
border-radius: 6px;
23-
padding: .5rem 1.5rem;
24-
line-height: 24px;
21+
margin: 1rem -1.5rem;
2522
background-color: var(--code-bg-color);
26-
overflow-x: auto;
2723
}
2824

29-
[class*='language-'] pre {
30-
position: relative;
31-
z-index: 1;
32-
background: transparent;
25+
li > div[class*='language-'] {
26+
border-radius: 6px 0 0 6px;
27+
margin: 1rem -1.5rem 1rem -1.25rem;
3328
}
3429

35-
[class*='language-'] code {
36-
padding: 0;
37-
color: #eee;
30+
@media (min-width: 420px) {
31+
div[class*='language-'] {
32+
margin: 1rem 0;
33+
border-radius: 6px;
34+
}
35+
36+
li > div[class*='language-'] {
37+
margin: 1rem 0 1rem 0rem;
38+
border-radius: 6px;
39+
}
3840
}
3941

40-
[class*='language-'] code,
41-
[class*='language-'] pre {
42+
[class*='language-'] pre,
43+
[class*='language-'] code {
4244
text-align: left;
4345
white-space: pre;
4446
word-spacing: normal;
4547
word-break: normal;
4648
word-wrap: normal;
47-
line-height: 24px;
4849
-moz-tab-size: 4;
4950
-o-tab-size: 4;
5051
tab-size: 4;
@@ -54,17 +55,34 @@ div[class*='language-'] {
5455
hyphens: none;
5556
}
5657

58+
[class*='language-'] pre {
59+
position: relative;
60+
z-index: 1;
61+
margin: 0;
62+
padding: 1.25rem 1.5rem;
63+
background: transparent;
64+
overflow-x: auto;
65+
}
66+
67+
[class*='language-'] code {
68+
padding: 0;
69+
line-height: var(--code-line-height);
70+
font-size: var(--code-font-size);
71+
color: #eee;
72+
}
73+
5774
/* Line highlighting */
5875

5976
.highlight-lines {
6077
position: absolute;
6178
top: 0;
79+
bottom: 0;
6280
left: 0;
63-
padding-top: var(--code-padding-vertical);
81+
padding: 1.25rem 0;
6482
width: 100%;
65-
line-height: 24px;
66-
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace;
67-
font-size: 14px;
83+
line-height: var(--code-line-height);
84+
font-family: var(--code-font-family);
85+
font-size: var(--code-font-size);
6886
user-select: none;
6987
}
7088

@@ -75,21 +93,23 @@ div[class*='language-'] {
7593
/* Line numbers mode */
7694

7795
div[class*='language-'].line-numbers-mode {
78-
padding-left: 5rem;
96+
padding-left: 3.5rem;
7997
}
8098

8199
.line-numbers-wrapper {
82100
position: absolute;
83101
top: 0;
102+
bottom: 0;
84103
left: 0;
104+
z-index: 3;
85105
border-right: 1px solid rgba(0, 0, 0, .5);
86-
padding: var(--code-padding-vertical) 0;
106+
padding: 1.25rem 0;
87107
width: 3.5rem;
88108
text-align: center;
89-
line-height: 24px;
90-
font-size: 16px;
109+
line-height: var(--code-line-height);
110+
font-family: var(--code-font-family);
111+
font-size: var(--code-font-size);
91112
color: #888;
92-
z-index: 4;
93113
}
94114

95115
/* Language marker */
@@ -98,7 +118,7 @@ div[class*='language-'].line-numbers-mode {
98118
position: absolute;
99119
top: .6em;
100120
right: 1em;
101-
z-index: 3;
121+
z-index: 2;
102122
font-size: .8rem;
103123
color: #888;
104124
}

src/client/theme-default/styles/layout.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
}
66

77
html {
8-
line-height: 1.15;
8+
line-height: 1.4;
9+
font-size: 16px;
910
-webkit-text-size-adjust: 100%;
1011
}
1112

src/client/theme-default/styles/vars.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* --------------------------------------------------------------------- */
2222

2323
--font-family-base: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
24+
--font-family-mono: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace;
2425

2526
/**
2627
* Z Indexes
@@ -46,7 +47,10 @@
4647

4748
--c-bg: var(--c-white);
4849

49-
--code-padding-vertical: 1.5rem;
50+
--code-line-height: 24px;
51+
--code-font-family: var(--font-family-mono);
52+
--code-font-size: 14px;
53+
--code-inline-bg-color: rgba(27, 31, 35, .05);
5054
--code-bg-color: #282c34;
5155

5256
}

0 commit comments

Comments
 (0)