Skip to content

Commit a67c3be

Browse files
authored
docs: remove rehype and replace with shiki (#7385)
* removed rehype-pretty-code and replaced with shiki * fix * fix
1 parent 62e5f9a commit a67c3be

File tree

5 files changed

+156
-213
lines changed

5 files changed

+156
-213
lines changed

packages/docs/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
"qwik-image": "0.0.10",
4444
"react": "18.3.1",
4545
"react-dom": "18.3.1",
46-
"rehype-pretty-code": "0.14.0",
47-
"shiki": "1.29.1",
4846
"snarkdown": "2.0.0",
4947
"tailwindcss": "3.4.6",
5048
"terser": "5.31.3",
@@ -54,6 +52,11 @@
5452
"valibot": "0.33.3",
5553
"vite": "5.3.5",
5654
"vite-plugin-inspect": "0.8.5",
55+
"shiki": "3.1.0",
56+
"@shikijs/rehype": "3.1.0",
57+
"@shikijs/transformers": "3.1.0",
58+
"@shikijs/colorized-brackets": "3.1.0",
59+
"@shikijs/types": "3.1.0",
5760
"wrangler": "3.65.1"
5861
},
5962
"engines": {

packages/docs/src/components/code-sandbox/index.tsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ export default component$<{
3030
))}
3131
</div>
3232
)}
33-
<div
34-
class="overflow-auto slot-container mb-4"
35-
style={{
36-
'--pretty-code-fragment-max-height': maxHeight ? maxHeight + 'px' : 'none',
37-
}}
38-
>
33+
<div class="overflow-auto slot-container mb-4">
3934
<Slot name={tabs ? String(activeTab.value) : ''} />
4035
</div>
4136
<div class="browser shadow-xl">

packages/docs/src/routes/docs/docs.css

+12-16
Original file line numberDiff line numberDiff line change
@@ -185,29 +185,25 @@ h6 a:hover .icon {
185185
font-weight: 800;
186186
}
187187

188-
[data-rehype-pretty-code-fragment] {
189-
overflow: auto;
190-
color: white;
191-
background-color: rgb(1 31 51);
192-
border-radius: 8px;
193-
margin: 20px 0;
188+
.highlighted-word {
189+
background: #4199d3;
190+
color: #111 !important;
194191
}
195192

196-
[data-rehype-pretty-code-fragment] pre {
197-
overflow: auto;
198-
border-radius: 8px;
199-
max-height: var(--pretty-code-fragment-max-height);
193+
.highlighted {
194+
background-color: #7b8d9f33 !important;
200195
}
201196

202-
[data-rehype-pretty-code-title] {
203-
padding: 5px 15px;
197+
.shiki-title {
204198
background: #4199d3;
205-
font-family: monospace;
206-
font-weight: bold;
199+
color: #111;
200+
display: block;
201+
padding: 0.5rem;
202+
border-radius: 8px 8px 0px 0px;
207203
}
208204

209-
[data-highlighted-chars] {
210-
background: #ac7ef4;
205+
pre {
206+
border-radius: 8px;
211207
}
212208

213209
.docs article pre {

packages/docs/vite.config.mts

+50-40
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import { defineConfig, loadEnv, type Plugin } from 'vite';
88
import Inspect from 'vite-plugin-inspect';
99
import { examplesData, playgroundData, rawSource, tutorialData } from './vite.repl-apps';
1010
import { sourceResolver } from './vite.source-resolver';
11+
import shikiRehype from '@shikijs/rehype';
12+
import { transformerMetaHighlight, transformerMetaWordHighlight } from '@shikijs/transformers';
13+
import { transformerColorizedBrackets } from '@shikijs/colorized-brackets';
14+
import type { ShikiTransformer } from '@shikijs/types';
1115

1216
const PUBLIC_QWIK_INSIGHTS_KEY = loadEnv('', '.', 'PUBLIC').PUBLIC_QWIK_INSIGHTS_KEY;
1317
const docsDir = new URL(import.meta.url).pathname;
@@ -52,9 +56,45 @@ const muteWarningsPlugin = (warningsToIgnore: string[][]): Plugin => {
5256
};
5357
};
5458

55-
export default defineConfig(async () => {
56-
const { default: rehypePrettyCode } = await import('rehype-pretty-code');
59+
function transformerShowEmptyLines(): ShikiTransformer {
60+
return {
61+
line(node) {
62+
if (node.children.length === 0) {
63+
node.children = [{ type: 'text', value: ' ' }];
64+
return node;
65+
}
66+
},
67+
};
68+
}
69+
70+
function transformerMetaShowTitle(): ShikiTransformer {
71+
return {
72+
root(node) {
73+
const meta = this.options.meta?.__raw;
74+
if (!meta) {
75+
return;
76+
}
77+
const titleMatch = meta.match(/title="([^"]*)"/);
78+
if (!titleMatch) {
79+
return;
80+
}
81+
const title = titleMatch[1] ?? '';
82+
if (title.length > 0) {
83+
node.children.unshift({
84+
type: 'element',
85+
tagName: 'div',
86+
properties: {
87+
class: 'shiki-title',
88+
},
89+
children: [{ type: 'text', value: title }],
90+
});
91+
}
92+
meta.replace(titleMatch[0], '');
93+
},
94+
};
95+
}
5796

97+
export default defineConfig(async () => {
5898
const routesDir = resolve('src', 'routes');
5999
return {
60100
dev: {
@@ -113,46 +153,16 @@ export default defineConfig(async () => {
113153
mdx: {
114154
rehypePlugins: [
115155
[
116-
rehypePrettyCode as any,
156+
shikiRehype,
117157
{
118158
theme: 'dark-plus',
119-
onVisitLine(node: any) {
120-
// Prevent lines from collapsing in `display: grid` mode, and
121-
// allow empty lines to be copy/pasted
122-
if (node.children.length === 0) {
123-
node.children = [{ type: 'text', value: ' ' }];
124-
}
125-
},
126-
onVisitHighlightedLine(node: any) {
127-
// Each line node by default has `class="line"`.
128-
if (node.properties.className) {
129-
node.properties.className.push('line--highlighted');
130-
}
131-
},
132-
onVisitHighlightedWord(node: any, id: string) {
133-
// Each word node has no className by default.
134-
node.properties.className = ['word'];
135-
if (id) {
136-
const backgroundColor = {
137-
a: 'rgb(196 42 94 / 59%)',
138-
b: 'rgb(0 103 163 / 56%)',
139-
c: 'rgb(100 50 255 / 35%)',
140-
}[id];
141-
142-
const color = {
143-
a: 'rgb(255 225 225 / 100%)',
144-
b: 'rgb(175 255 255 / 100%)',
145-
c: 'rgb(225 200 255 / 100%)',
146-
}[id];
147-
if (node.properties['data-rehype-pretty-code-wrapper']) {
148-
node.children.forEach((childNode: any) => {
149-
childNode.properties.style = ``;
150-
childNode.properties.className = '';
151-
});
152-
}
153-
node.properties.style = `background-color: ${backgroundColor}; color: ${color};`;
154-
}
155-
},
159+
transformers: [
160+
transformerMetaHighlight(),
161+
transformerMetaWordHighlight(),
162+
transformerColorizedBrackets(),
163+
transformerShowEmptyLines(),
164+
transformerMetaShowTitle(),
165+
],
156166
},
157167
],
158168
],

0 commit comments

Comments
 (0)