Skip to content

Commit 7f9f7e1

Browse files
committed
Enable syntax highlighting for docs code blocks
1 parent 0cdeb83 commit 7f9f7e1

4 files changed

Lines changed: 127 additions & 1 deletion

File tree

site/package-lock.json

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

site/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"react-dom": "^19.2.0",
1818
"react-markdown": "^10.1.0",
1919
"react-router-dom": "^7.13.1",
20+
"rehype-highlight": "^7.0.2",
2021
"remark-gfm": "^4.0.1"
2122
},
2223
"devDependencies": {

site/src/App.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Navigate, NavLink, Route, Routes, useParams } from 'react-router-dom'
22
import ReactMarkdown from 'react-markdown'
33
import remarkGfm from 'remark-gfm'
4+
import rehypeHighlight from 'rehype-highlight'
45
import { docs, getDocBySlug, getDocContent, getDocNeighbors, isDocSlug } from './content/docRegistry'
56

67
function App() {
@@ -151,7 +152,9 @@ function DocsPage() {
151152
</div>
152153

153154
<article className="doc-markdown">
154-
<ReactMarkdown remarkPlugins={[remarkGfm]}>{markdown}</ReactMarkdown>
155+
<ReactMarkdown remarkPlugins={[remarkGfm]} rehypePlugins={[rehypeHighlight]}>
156+
{markdown}
157+
</ReactMarkdown>
155158
</article>
156159

157160
<div className="mt-10 grid gap-3 border-t border-[var(--line)] pt-5 sm:grid-cols-2">

site/src/index.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,43 @@ a {
252252
font-size: 0.94em;
253253
}
254254

255+
.doc-markdown pre code.hljs {
256+
color: color-mix(in srgb, var(--text), white 8%);
257+
background: transparent;
258+
}
259+
260+
.doc-markdown .hljs-keyword,
261+
.doc-markdown .hljs-selector-tag,
262+
.doc-markdown .hljs-literal,
263+
.doc-markdown .hljs-type {
264+
color: #d97706;
265+
}
266+
267+
.doc-markdown .hljs-string,
268+
.doc-markdown .hljs-attr,
269+
.doc-markdown .hljs-template-tag,
270+
.doc-markdown .hljs-template-variable {
271+
color: #0891b2;
272+
}
273+
274+
.doc-markdown .hljs-number,
275+
.doc-markdown .hljs-symbol,
276+
.doc-markdown .hljs-bullet {
277+
color: #a855f7;
278+
}
279+
280+
.doc-markdown .hljs-title,
281+
.doc-markdown .hljs-function,
282+
.doc-markdown .hljs-class .hljs-title {
283+
color: #16a34a;
284+
}
285+
286+
.doc-markdown .hljs-comment,
287+
.doc-markdown .hljs-quote {
288+
color: color-mix(in srgb, var(--text-dim), var(--surface) 25%);
289+
font-style: italic;
290+
}
291+
255292
.doc-markdown blockquote {
256293
margin: 1rem 0;
257294
border-left: 3px solid var(--teal);

0 commit comments

Comments
 (0)