Skip to content

Commit 2a4a3ab

Browse files
committed
Added themes and css styling for mdx
1 parent 5c3c0f6 commit 2a4a3ab

File tree

3 files changed

+116
-2
lines changed

3 files changed

+116
-2
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"rehype-pretty-code": "^0.12.5",
3535
"remark-gfm": "^4.0.0",
3636
"remark-smartypants": "^2.1.0",
37+
"shiki-themes": "^0.2.7",
3738
"shikiji": "^0.10.0-beta.9",
3839
"tailwind-merge": "^2.2.0",
3940
"tailwindcss-animate": "^1.0.7",

src/app/articles/[slug]/markdown.css

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
.markdown {
2+
line-height: 28px;
3+
--path: none;
4+
--radius-top: 12px;
5+
--radius-bottom: 12px;
6+
--padding-top: 1rem;
7+
--padding-bottom: 1rem;
8+
}
9+
10+
.markdown p {
11+
@apply pb-8;
12+
}
13+
14+
.markdown a {
15+
@apply border-b-[1px] border-[--link] text-[--link];
16+
}
17+
18+
.markdown hr {
19+
@apply pt-8 opacity-60 dark:opacity-10;
20+
}
21+
22+
.markdown h2 {
23+
@apply mt-2 pb-8 text-3xl font-bold;
24+
}
25+
26+
.markdown h3 {
27+
@apply mt-2 pb-8 text-2xl font-bold;
28+
}
29+
30+
.markdown h4 {
31+
@apply mt-2 pb-8 text-xl font-bold;
32+
}
33+
34+
.markdown :not(pre)>code {
35+
border-radius: 10px;
36+
background: var(--inlineCode-bg);
37+
color: var(--inlineCode-text);
38+
padding: 0.15em 0.2em 0.05em;
39+
white-space: normal;
40+
}
41+
42+
.markdown pre {
43+
@apply -mx-4 mb-8 overflow-y-auto p-4 text-sm;
44+
clip-path: var(--path);
45+
border-top-right-radius: var(--radius-top);
46+
border-top-left-radius: var(--radius-top);
47+
border-bottom-right-radius: var(--radius-bottom);
48+
border-bottom-left-radius: var(--radius-bottom);
49+
padding-top: var(--padding-top);
50+
padding-bottom: var(--padding-bottom);
51+
}
52+
53+
.markdown pre code {
54+
width: auto;
55+
border: 1px solid #d1d5db;
56+
/* light gray border, you can use any color */
57+
border-radius: 5px;
58+
/* optional: if you want rounded corners */
59+
padding: 1em;
60+
/* optional: adds some space inside the borders */
61+
overflow: auto;
62+
/* optional: adds a scrollbar if the content is too wide */
63+
background-color: #f8f8f8;
64+
}
65+
66+
.markdown blockquote {
67+
@apply relative -left-2 -ml-4 mb-8 pl-4;
68+
font-style: italic;
69+
border-left: 3px solid hsla(0, 0%, 0%, 0.9);
70+
border-left-color: inherit;
71+
opacity: 0.8;
72+
}
73+
74+
.markdown blockquote p {
75+
margin: 0;
76+
padding: 0;
77+
}
78+
79+
.markdown p img {
80+
margin-bottom: 0;
81+
}
82+
83+
.markdown ul {
84+
margin-top: 0;
85+
padding-bottom: 0;
86+
padding-left: 0;
87+
padding-right: 0;
88+
padding-top: 0;
89+
margin-bottom: 1.75rem;
90+
list-style-position: outside;
91+
list-style-image: none;
92+
list-style: disc;
93+
}
94+
95+
.markdown li {
96+
margin-bottom: calc(1.75rem / 2);
97+
}
98+
99+
.markdown img {
100+
@apply mb-8;
101+
max-width: 100%;
102+
}
103+
104+
.markdown pre [data-highlighted-line] {
105+
margin-left: -16px;
106+
padding-left: 12px;
107+
border-left: 4px solid #ffa7c4;
108+
background-color: #022a4b;
109+
display: block;
110+
padding-right: 1em;
111+
}

src/app/articles/[slug]/page.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { MDXRemote } from "next-mdx-remote/rsc";
22
import remarkSmartpants from "remark-smartypants";
33
import rehypePrettyCode from "rehype-pretty-code";
4-
import { readdir, readFile } from "fs/promises";
4+
import { readFile } from "fs/promises";
55
import overnight from "overnight/themes/Overnight-Slumber.json";
66
import matter from "gray-matter";
7+
import "./markdown.css";
8+
import githubLight from "shiki-themes/data/github-light.json";
79

810
export default async function Article({
911
params: { slug },
@@ -52,7 +54,7 @@ export default async function Article({
5254
[
5355
rehypePrettyCode as any,
5456
{
55-
theme: overnight,
57+
theme: githubLight,
5658
},
5759
],
5860
],

0 commit comments

Comments
 (0)