Skip to content

Commit 45ec5bf

Browse files
authored
docs: replace prismjs with shiki 🎁 (#7838)
1 parent 501a42e commit 45ec5bf

File tree

7 files changed

+25
-44
lines changed

7 files changed

+25
-44
lines changed

β€Žpackages/docs/package.jsonβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"@supabase/supabase-js": "2.53.0",
2727
"@tailwindcss/vite": "4.1.11",
2828
"@types/leaflet": "1.9.20",
29-
"@types/prismjs": "1.26.5",
3029
"@types/react": "18.3.3",
3130
"@types/react-dom": "18.3.0",
3231
"@unpic/core": "0.0.42",
@@ -39,7 +38,6 @@
3938
"openai": "3.3.0",
4039
"prettier": "3.6.2",
4140
"prism-themes": "1.9.0",
42-
"prismjs": "1.30.0",
4341
"puppeteer": "22.13.1",
4442
"qwik-image": "0.0.16",
4543
"react": "18.3.1",

β€Žpackages/docs/src/components/code-block/code-block.tsxβ€Ž

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { component$, useSignal, useStyles$, useVisibleTask$, type QRL } from '@builder.io/qwik';
2-
32
import { CopyCode } from '../copy-code/copy-code-block';
43
import styles from './code-block.css?inline';
5-
import { highlight } from './prismjs';
4+
import { shikiInstance, SHIKI_THEME, type ShikiLangs } from './shiki-config';
5+
66
interface CodeBlockProps {
77
path?: string;
8-
language?: 'markup' | 'css' | 'javascript' | 'json' | 'jsx' | 'tsx';
8+
language?: ShikiLangs;
99
code: string;
1010
pathInView$?: QRL<(name: string) => void>;
1111
observerRootId?: string;
@@ -36,17 +36,13 @@ export const CodeBlock = component$((props: CodeBlockProps) => {
3636
let language = props.language;
3737
if (!language && props.path && props.code) {
3838
const ext = props.path.split('.').pop();
39-
language =
40-
ext === 'js' || ext === 'json'
41-
? 'javascript'
42-
: ext === 'html'
43-
? 'markup'
44-
: ext === 'css'
45-
? 'css'
46-
: undefined;
39+
language = ext === 'js' || ext === 'json' ? 'javascript' : ext === 'css' ? 'css' : 'html';
4740
}
4841

49-
const highlighted = highlight(props.code, language);
42+
const highlighted = shikiInstance.codeToHtml(props.code, {
43+
lang: language!,
44+
theme: SHIKI_THEME,
45+
});
5046
const className = `language-${language}`;
5147
return (
5248
<div class="relative">

β€Žpackages/docs/src/components/code-block/prismjs.tsβ€Ž

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { createHighlighter } from 'shiki/bundle/web';
2+
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
3+
4+
export const SHIKI_THEME = 'dark-plus';
5+
6+
const shikiLangs = ['html', 'css', 'javascript', 'json', 'jsx', 'tsx'] as const;
7+
export type ShikiLangs = (typeof shikiLangs)[number];
8+
9+
const jsEngine = createJavaScriptRegexEngine();
10+
export const shikiInstance = await createHighlighter({
11+
themes: [SHIKI_THEME],
12+
langs: [...shikiLangs],
13+
engine: jsEngine,
14+
});

β€Žpackages/docs/src/repl/repl-output-panel.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const ReplOutputPanel = component$(({ input, store }: ReplOutputPanelProp
102102

103103
{store.selectedOutputPanel === 'html' ? (
104104
<div class="output-result output-html">
105-
<CodeBlock language="markup" code={store.html} />
105+
<CodeBlock language="html" code={store.html} />
106106
</div>
107107
) : null}
108108

β€Žpackages/docs/tsconfig.jsonβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"compilerOptions": {
33
"incremental": true,
4-
"target": "ES2020",
5-
"module": "ES2020",
4+
"target": "es2022",
5+
"module": "es2022",
66
"lib": ["es2021", "DOM", "webworker", "DOM.Iterable"],
77
"resolveJsonModule": true,
88
"jsx": "react-jsx",

β€Žpnpm-lock.yamlβ€Ž

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

0 commit comments

Comments
Β (0)