Skip to content

Commit cf6b4b4

Browse files
committed
feat(website): add syntax highlight
1 parent e99a985 commit cf6b4b4

6 files changed

Lines changed: 177 additions & 17 deletions

File tree

pnpm-lock.yaml

Lines changed: 40 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/contentlayer.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineDocumentType, makeSource } from 'contentlayer/source-files';
2+
import rehypeHighlight from 'rehype-highlight';
23

34
export const Doc = defineDocumentType(() => ({
45
name: 'Doc',
@@ -21,4 +22,7 @@ export const Doc = defineDocumentType(() => ({
2122
export default makeSource({
2223
contentDirPath: 'contents',
2324
documentTypes: [Doc],
25+
mdx: {
26+
rehypePlugins: [rehypeHighlight],
27+
},
2428
});

website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"postcss": "^8.4.16",
2929
"prettier": "2.7.1",
3030
"prettier-plugin-tailwindcss": "0.1.13",
31+
"rehype-highlight": "5.0.2",
3132
"tailwindcss": "^3.1.8",
3233
"typescript": "^4.8.3"
3334
}

website/pages/_app.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Aside from '~/modules/layout/components/Aside';
55
import Header from '~/modules/layout/components/Header';
66

77
import '../styles/globals.css';
8+
import '../styles/syntax-highlight.css';
89
import '../styles/variables.css';
910

1011
interface PageProps {

website/styles/globals.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
@tailwind base;
22
@tailwind components;
33
@tailwind utilities;
4+
5+
@layer base {
6+
.prose code.hljs {
7+
@apply bg-transparent;
8+
}
9+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*!
2+
Theme: GitHub Dark
3+
Description: Dark theme as seen on github.com
4+
Author: github.com
5+
Maintainer: @Hirse
6+
Updated: 2021-05-15
7+
8+
Outdated base version: https://github.com/primer/github-syntax-dark
9+
Current colors taken from GitHub's CSS
10+
*/
11+
12+
.hljs {
13+
color: #c9d1d9;
14+
background: #0d1117;
15+
}
16+
17+
.hljs-doctag,
18+
.hljs-keyword,
19+
.hljs-meta .hljs-keyword,
20+
.hljs-template-tag,
21+
.hljs-template-variable,
22+
.hljs-type,
23+
.hljs-variable.language_ {
24+
/* prettylights-syntax-keyword */
25+
color: #ff7b72;
26+
}
27+
28+
.hljs-title,
29+
.hljs-title.class_,
30+
.hljs-title.class_.inherited__,
31+
.hljs-title.function_ {
32+
/* prettylights-syntax-entity */
33+
color: #d2a8ff;
34+
}
35+
36+
.hljs-attr,
37+
.hljs-attribute,
38+
.hljs-literal,
39+
.hljs-meta,
40+
.hljs-number,
41+
.hljs-operator,
42+
.hljs-variable,
43+
.hljs-selector-attr,
44+
.hljs-selector-class,
45+
.hljs-selector-id {
46+
/* prettylights-syntax-constant */
47+
color: #79c0ff;
48+
}
49+
50+
.hljs-regexp,
51+
.hljs-string,
52+
.hljs-meta .hljs-string {
53+
/* prettylights-syntax-string */
54+
color: #a5d6ff;
55+
}
56+
57+
.hljs-built_in,
58+
.hljs-symbol {
59+
/* prettylights-syntax-variable */
60+
color: #ffa657;
61+
}
62+
63+
.hljs-comment,
64+
.hljs-code,
65+
.hljs-formula {
66+
/* prettylights-syntax-comment */
67+
color: #8b949e;
68+
}
69+
70+
.hljs-name,
71+
.hljs-quote,
72+
.hljs-selector-tag,
73+
.hljs-selector-pseudo {
74+
/* prettylights-syntax-entity-tag */
75+
color: #7ee787;
76+
}
77+
78+
.hljs-subst {
79+
/* prettylights-syntax-storage-modifier-import */
80+
color: #c9d1d9;
81+
}
82+
83+
.hljs-section {
84+
/* prettylights-syntax-markup-heading */
85+
color: #1f6feb;
86+
font-weight: bold;
87+
}
88+
89+
.hljs-bullet {
90+
/* prettylights-syntax-markup-list */
91+
color: #f2cc60;
92+
}
93+
94+
.hljs-emphasis {
95+
/* prettylights-syntax-markup-italic */
96+
color: #c9d1d9;
97+
font-style: italic;
98+
}
99+
100+
.hljs-strong {
101+
/* prettylights-syntax-markup-bold */
102+
color: #c9d1d9;
103+
font-weight: bold;
104+
}
105+
106+
.hljs-addition {
107+
/* prettylights-syntax-markup-inserted */
108+
color: #aff5b4;
109+
background-color: #033a16;
110+
}
111+
112+
.hljs-deletion {
113+
/* prettylights-syntax-markup-deleted */
114+
color: #ffdcd7;
115+
background-color: #67060c;
116+
}
117+
118+
.hljs-char.escape_,
119+
.hljs-link,
120+
.hljs-params,
121+
.hljs-property,
122+
.hljs-punctuation,
123+
.hljs-tag {
124+
/* purposely ignored */
125+
}

0 commit comments

Comments
 (0)