Skip to content

Commit f41da01

Browse files
committed
Revert "docs: replace prismjs with shiki 🎁 (#7838)"
This reverts commit 45ec5bf. Turns out that shiki is a lot slower than prismjs, which makes switching to the code panels very slow.
1 parent 18f84a8 commit f41da01

File tree

6 files changed

+40
-33
lines changed

6 files changed

+40
-33
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@supabase/supabase-js": "2.53.0",
3030
"@tailwindcss/vite": "4.1.11",
3131
"@types/leaflet": "1.9.20",
32+
"@types/prismjs": "1.26.5",
3233
"@types/react": "18.3.3",
3334
"@types/react-dom": "18.3.0",
3435
"@unpic/core": "0.0.42",
@@ -41,6 +42,7 @@
4142
"openai": "3.3.0",
4243
"prettier": "3.6.2",
4344
"prism-themes": "1.9.0",
45+
"prismjs": "1.30.0",
4446
"puppeteer": "22.13.1",
4547
"qwik-image": "0.0.16",
4648
"react": "18.3.1",

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import {
77
type QRL,
88
type Signal,
99
} from '@builder.io/qwik';
10+
1011
import { CopyCode } from '../copy-code/copy-code-block';
1112
import styles from './code-block.css?inline';
12-
import { shikiInstance, SHIKI_THEME, type ShikiLangs } from './shiki-config';
13+
import { highlight } from './prismjs';
1314
import { format } from 'prettier/standalone';
1415
import parserHtml from 'prettier/plugins/html';
1516
import parserTs from 'prettier/plugins/typescript';
1617
import parserEstree from 'prettier/plugins/estree';
17-
1818
interface CodeBlockProps {
1919
path?: string;
20-
language?: ShikiLangs;
20+
language?: 'markup' | 'css' | 'javascript' | 'json' | 'jsx' | 'tsx';
2121
code: string;
2222
format?: boolean;
2323
pathInView$?: QRL<(name: string) => void>;
@@ -36,8 +36,10 @@ export const CodeBlock = component$((props: CodeBlockProps) => {
3636
? /\.([cm]?[jt]sx?|json)$/.test(props.path)
3737
? 'javascript'
3838
: props.path.endsWith('.html')
39-
? 'html'
40-
: null
39+
? 'markup'
40+
: props.path.endsWith('.css')
41+
? 'css'
42+
: null
4143
: null);
4244

4345
useStyles$(styles);
@@ -49,7 +51,7 @@ export const CodeBlock = component$((props: CodeBlockProps) => {
4951
if (formatSig.value) {
5052
try {
5153
// simple formatting for html and js
52-
if (language === 'html') {
54+
if (language === 'markup') {
5355
codeSig.value = await format(props.code, {
5456
parser: 'html',
5557
plugins: [parserHtml],
@@ -90,18 +92,14 @@ export const CodeBlock = component$((props: CodeBlockProps) => {
9092
});
9193

9294
const highlighted =
93-
codeSig.value != null &&
94-
shikiInstance.codeToHtml(codeSig.value, {
95-
lang: language!,
96-
theme: SHIKI_THEME,
97-
});
95+
codeSig.value != null && language ? highlight(codeSig.value, language) : codeSig.value;
9896
const className = `language-${language}`;
9997
return (
10098
<div class="relative">
10199
<pre class={className} ref={listSig}>
102100
{highlighted && <code class={className} dangerouslySetInnerHTML={highlighted} />}
103101
</pre>
104-
{(language === 'html' || language === 'javascript') && (
102+
{(language === 'markup' || language === 'javascript') && (
105103
<PrettierToggle bind:value={formatSig} />
106104
)}
107105
<CopyCode code={props.code} />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import prismjs from 'prismjs';
2+
import 'prismjs/components/prism-jsx';
3+
import 'prismjs/components/prism-tsx';
4+
5+
export const highlight = (code?: string, language?: string) => {
6+
if (!code || !language || !prismjs.languages[language]) {
7+
return `<code class="language-${language}"><pre>${code}</pre></code>`;
8+
}
9+
return prismjs.highlight(code, prismjs.languages[language], language);
10+
};

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

Lines changed: 0 additions & 20 deletions
This file was deleted.

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

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

112112
{store.selectedOutputPanel === 'html' ? (
113113
<div class="output-result output-html">
114-
<CodeBlock language="html" format code={store.html} />
114+
<CodeBlock language="markup" format code={store.html} />
115115
</div>
116116
) : null}
117117

β€Žpnpm-lock.yamlβ€Ž

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

0 commit comments

Comments
Β (0)