Skip to content

Commit 4d00dcf

Browse files
authored
use custom Shiki themes based on default GitHub ones (#2100)
1 parent 654f919 commit 4d00dcf

File tree

5 files changed

+1236
-10
lines changed

5 files changed

+1236
-10
lines changed

components/Package/ReadmeBox.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Md } from '@m2d/react-markdown/client';
22
import { capitalize } from 'es-toolkit';
33
import { useEffect, useState } from 'react';
44
import { View } from 'react-native';
5+
import { type Theme } from 'react-shiki';
56
import rehypeRaw from 'rehype-raw';
67
import rehypeSanitize from 'rehype-sanitize';
78
import remarkEmoji from 'remark-emoji';
@@ -11,6 +12,8 @@ import { A, P } from '~/common/styleguide';
1112
import { ReadmeFile } from '~/components/Icons';
1213
import ReadmeCodeBlock from '~/components/Package/ReadmeCodeBlock';
1314
import { ThreeDotsLoader } from '~/components/Package/ThreeDotsLoader';
15+
import rndDark from '~/styles/shiki/rnd-dark.json';
16+
import rndLight from '~/styles/shiki/rnd-light.json';
1417
import { extractAndStripBlockquoteType } from '~/util/extractAndStripBlockquoteType';
1518
import { getReadmeAssetURL } from '~/util/getReadmeAssetUrl';
1619
import tw from '~/util/tailwind';
@@ -156,6 +159,7 @@ export default function ReadmeBox({ packageName, githubUrl, isTemplate, loader =
156159
return (
157160
<ReadmeCodeBlock
158161
code={children.props.children}
162+
theme={(tw.prefixMatch('dark') ? rndDark : rndLight) as Theme}
159163
lang={langClass ? (langClass.split('-')[1] ?? 'sh').toLowerCase() : 'sh'}
160164
/>
161165
);

components/Package/ReadmeCodeBlock.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useShikiHighlighter } from 'react-shiki';
1+
import { type Theme, useShikiHighlighter } from 'react-shiki';
22

33
import { Button } from '~/components/Button';
44
import { Copy } from '~/components/Icons';
@@ -8,17 +8,13 @@ import tw from '~/util/tailwind';
88
type Props = {
99
code: string;
1010
lang: string;
11+
theme: Theme;
1112
};
1213

13-
export default function ReadmeCodeBlock({ code, lang }: Props) {
14-
const highlighter = useShikiHighlighter(
15-
code,
16-
lang,
17-
tw.prefixMatch('dark') ? 'github-dark-default' : 'github-light-default',
18-
{
19-
langAlias: { gradle: 'groovy' },
20-
}
21-
);
14+
export default function ReadmeCodeBlock({ code, theme, lang }: Props) {
15+
const highlighter = useShikiHighlighter(code, lang, theme, {
16+
langAlias: { gradle: 'groovy' },
17+
});
2218

2319
const copyButton = (
2420
<Tooltip

next.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const PACKAGES_TO_OPTIMIZE = [
99
'@expo/html-elements',
1010
'@react-native-picker/picker',
1111
'@sentry/*',
12+
'@shikijs/*',
1213
'node-emoji',
1314
'react-native',
1415
'react-native-safe-area-context',

0 commit comments

Comments
 (0)