Skip to content

Commit cd65030

Browse files
committed
chore: update shiki
1 parent ca6fba1 commit cd65030

File tree

13 files changed

+130
-251
lines changed

13 files changed

+130
-251
lines changed

apps/component-tests/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"jsxImportSource": "@builder.io/qwik",
1010
"strict": true,
1111
"resolveJsonModule": true,
12-
"moduleResolution": "node",
12+
"moduleResolution": "bundler",
1313
"esModuleInterop": true,
1414
"skipLibCheck": true,
1515
"incremental": true,

apps/website/src/components/highlight/highlight.tsx

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,25 @@
1-
import {
2-
type ClassList,
3-
type PropsOf,
4-
component$,
5-
useSignal,
6-
useTask$,
7-
$,
8-
} from '@builder.io/qwik';
1+
import { type ClassList, type PropsOf, component$ } from '@builder.io/qwik';
92
import { CodeCopy } from '../code-copy/code-copy';
103
import { cn } from '@qwik-ui/utils';
11-
import { codeToHtml } from 'shiki';
4+
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
5+
import { createHighlighter } from 'shiki/bundle/web';
6+
7+
const jsEngine = createJavaScriptRegexEngine();
8+
9+
const shiki = await createHighlighter({
10+
themes: ['poimandres'],
11+
langs: ['tsx', 'html', 'css'],
12+
engine: jsEngine,
13+
});
1214

1315
export type HighlightProps = PropsOf<'div'> & {
1416
code: string;
1517
copyCodeClass?: ClassList;
1618
language?: 'tsx' | 'html' | 'css';
17-
splitCommentStart?: string;
18-
splitCommentEnd?: string;
1919
};
2020

2121
export const Highlight = component$(
22-
({
23-
code,
24-
copyCodeClass,
25-
language = 'tsx',
26-
splitCommentStart = '{/* start */}',
27-
splitCommentEnd = '{/* end */}',
28-
...props
29-
}: HighlightProps) => {
30-
const codeSig = useSignal('');
31-
32-
const addShiki$ = $(async () => {
33-
let modifiedCode: string = code;
34-
35-
let partsOfCode = modifiedCode.split(splitCommentStart);
36-
37-
if (partsOfCode.length > 1) {
38-
modifiedCode = partsOfCode[1];
39-
}
40-
41-
partsOfCode = modifiedCode.split(splitCommentEnd);
42-
43-
if (partsOfCode.length > 1) {
44-
modifiedCode = partsOfCode[0];
45-
}
46-
47-
const str = await codeToHtml(modifiedCode, {
48-
lang: language,
49-
theme: 'poimandres',
50-
});
51-
52-
codeSig.value = str.toString();
53-
});
54-
55-
useTask$(async ({ track }) => {
56-
track(() => code);
57-
await addShiki$();
58-
});
59-
22+
({ code, copyCodeClass, language = 'tsx', ...props }: HighlightProps) => {
6023
return (
6124
<div class="code-example data-pagefind-ignore relative max-h-[31.25rem] rounded-base">
6225
<CodeCopy
@@ -74,7 +37,12 @@ export const Highlight = component$(
7437
)}
7538
data-pagefind-ignore="all"
7639
>
77-
<div dangerouslySetInnerHTML={codeSig.value} />
40+
<div
41+
dangerouslySetInnerHTML={shiki.codeToHtml(code, {
42+
lang: language,
43+
theme: 'poimandres',
44+
})}
45+
/>
7846
</div>
7947
</div>
8048
);

apps/website/src/components/mdx-components/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ export const components: Record<string, Component> = {
109109
);
110110
}),
111111
pre: component$<{
112-
__rawString__?: string;
113-
}>(({ __rawString__ }) => {
112+
rawCodeString?: string;
113+
}>(({ rawCodeString }) => {
114114
return (
115115
<div
116116
class="code-example data-pagefind-ignore relative mb-6 max-h-[31.25rem] rounded-base"
117117
data-pagefind-ignore="all"
118118
>
119-
<CodeCopy class="absolute right-3 top-3" code={__rawString__} />
119+
<CodeCopy class="absolute right-3 top-3" code={rawCodeString} />
120120
<div
121121
class={cn(
122122
'max-h-[31.25rem] max-w-full overflow-y-auto rounded-base border bg-gradient-to-b from-slate-900 to-slate-800 p-6 text-sm dark:from-background dark:to-accent/30',

apps/website/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"jsxImportSource": "@builder.io/qwik",
1010
"strict": true,
1111
"resolveJsonModule": true,
12-
"moduleResolution": "node",
12+
"moduleResolution": "bundler",
1313
"esModuleInterop": true,
1414
"skipLibCheck": true,
1515
"incremental": true,

apps/website/vite.config.ts

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { defineConfig } from 'vite';
44
import tsconfigPaths from 'vite-tsconfig-paths';
55
import { recmaProvideComponents } from './recma-provide-components';
66
import autoAPI from './auto-api';
7+
import { ShikiTransformer } from 'shiki';
78

89
export default defineConfig(async () => {
9-
const { default: rehypePrettyCode } = await import('rehype-pretty-code');
10-
const { visit } = await import('unist-util-visit');
10+
const { default: shikiRehype } = await import('@shikijs/rehype');
1111

1212
return {
1313
plugins: [
@@ -22,37 +22,13 @@ export default defineConfig(async () => {
2222
providerImportSource: '~/_state/MDXProvider',
2323
recmaPlugins: [recmaProvideComponents],
2424
rehypePlugins: [
25-
() => (tree) => {
26-
visit(tree, (node) => {
27-
if (node?.type === 'element' && node?.tagName === 'pre') {
28-
const [codeEl] = node.children;
29-
if (codeEl.tagName !== 'code') {
30-
return;
31-
}
32-
node.__rawString__ = codeEl.children?.[0].value;
33-
}
34-
});
35-
},
3625
[
37-
rehypePrettyCode,
26+
shikiRehype,
3827
{
3928
theme: 'poimandres',
29+
transformers: [transformerSourceAsPreProp()],
4030
},
4131
],
42-
() => (tree) => {
43-
visit(tree, (node) => {
44-
if (node?.type === 'element' && node?.tagName === 'figure') {
45-
if (!('data-rehype-pretty-code-figure' in node.properties)) {
46-
return;
47-
}
48-
const preElement = node.children.at(-1);
49-
if (preElement.tagName !== 'pre') {
50-
return;
51-
}
52-
preElement.properties['__rawString__'] = node.__rawString__;
53-
}
54-
});
55-
},
5632
],
5733
},
5834
}),
@@ -101,10 +77,13 @@ export default defineConfig(async () => {
10177
'Cache-Control': 'public, max-age=600',
10278
},
10379
},
104-
optimizeDeps: {
105-
// Put problematic deps that break bundling here, mostly those with binaries.
106-
// For example ['better-sqlite3'] if you use that in server functions.
107-
exclude: ['shiki'],
108-
},
10980
};
11081
});
82+
83+
function transformerSourceAsPreProp(): ShikiTransformer {
84+
return {
85+
pre(node) {
86+
node.properties.rawCodeString = this.source;
87+
},
88+
};
89+
}

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
"@oddbird/popover-polyfill": "0.4.3",
7373
"@playwright/test": "^1.44.1",
7474
"@qwikest/icons": "^0.0.13",
75+
"@shikijs/rehype": "3.4.2",
76+
"@shikijs/transformers": "3.4.2",
7577
"@swc-node/register": "^1.9.1",
7678
"@swc/core": "^1.5.7",
7779
"@types/decompress": "4.2.7",
@@ -114,10 +116,8 @@
114116
"prettier-plugin-tailwindcss": "^0.5.14",
115117
"pretty-quick": "^4.0.0",
116118
"qwik-nx": "^2.3.0",
117-
"qwik-themes": "^0.2.0",
118-
"rehype-pretty-code": "^0.13.2",
119119
"sass": "^1.77.2",
120-
"shiki": "^1.21.0",
120+
"shiki": "^3.4.2",
121121
"simple-git-hooks": "2.11.1",
122122
"specificity": "^1.0.0",
123123
"tailwind-merge": "^2.3.0",
@@ -130,7 +130,6 @@
130130
"typescript": "5.4.5",
131131
"undici": "5.28.4",
132132
"unified": "^11.0.4",
133-
"unist-util-visit": "^5.0.0",
134133
"verdaccio": "^5.31.0",
135134
"vite": "5.2.11",
136135
"vite-plugin-dts": "^3.9.1",

packages/kit-headless/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"noImplicitReturns": true,
1313
"noFallthroughCasesInSwitch": true,
1414
"resolveJsonModule": true,
15-
"moduleResolution": "node",
15+
"moduleResolution": "bundler",
1616
"esModuleInterop": true,
1717
"skipLibCheck": true,
1818
"incremental": true,

packages/kit-styled/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"noImplicitReturns": true,
1313
"noFallthroughCasesInSwitch": true,
1414
"resolveJsonModule": true,
15-
"moduleResolution": "node",
15+
"moduleResolution": "bundler",
1616
"esModuleInterop": true,
1717
"skipLibCheck": true,
1818
"incremental": true,

packages/themes/project.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
"projectType": "library",
66
"targets": {
77
"build": {
8-
"executor": "@nx/js:tsc",
8+
"executor": "@nx/vite:build",
99
"outputs": ["{options.outputPath}"],
10+
"defaultConfiguration": "production",
1011
"options": {
11-
"main": "src/index.ts",
1212
"outputPath": "dist/packages/themes",
13-
"tsConfig": "packages/themes/tsconfig.lib.json"
13+
"configFile": "packages/themes/vite.config.ts",
14+
"mode": "lib"
15+
},
16+
"configurations": {
17+
"development": {},
18+
"production": {}
1419
}
1520
},
1621
"lint": {

packages/themes/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"noImplicitReturns": true,
1313
"noFallthroughCasesInSwitch": true,
1414
"resolveJsonModule": true,
15-
"moduleResolution": "node",
15+
"moduleResolution": "bundler",
1616
"esModuleInterop": true,
1717
"skipLibCheck": true,
1818
"incremental": true,

packages/utils/src/theme/extract-theme-css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Theme } from 'qwik-themes/lib-types/lib/types';
1+
import { Theme } from '@qwik-ui/themes';
22
import { calculate, compare } from 'specificity';
33
import { extractBetweenComments } from './extract-between-comments';
44

0 commit comments

Comments
 (0)