Skip to content

Commit 8c1a2c3

Browse files
committed
feat: jsx copy button hook
1 parent 461abfb commit 8c1a2c3

22 files changed

+1164
-649
lines changed

docs/astro.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default defineConfig({
6262
theme: moonlightTheme as unknown as RawTheme,
6363
transformers: [
6464
transformerCopyButton({
65-
visibility: 'hover',
65+
visibility: 'always',
6666
feedbackDuration: 2_500,
6767
}),
6868
],

docs/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@
1111
"astro": "astro"
1212
},
1313
"dependencies": {
14-
"@astrojs/mdx": "^3.1.2",
14+
"@astrojs/mdx": "^3.1.3",
1515
"@astrojs/starlight": "^0.25.1",
1616
"@astrojs/starlight-tailwind": "^2.0.3",
1717
"@astrojs/tailwind": "^5.1.0",
1818
"@rehype-pretty/transformers": "workspace:*",
19-
"astro": "^4.11.5",
19+
"astro": "^4.12.2",
2020
"rehype-autolink-headings": "^7.1.0",
2121
"rehype-pretty-code": "workspace:*",
2222
"rehype-slug": "^6.0.0",
2323
"rehype-stringify": "^10.0.0",
2424
"remark-toc": "^9.0.0",
2525
"sharp": "^0.33.4",
26-
"shiki": "^1.10.3",
27-
"tailwindcss": "^3.4.5"
26+
"shiki": "^1.11.0",
27+
"tailwindcss": "^3.4.6"
2828
},
2929
"devDependencies": {
30-
"@astrojs/check": "^0.8.1",
31-
"@shikijs/transformers": "^1.10.3",
32-
"@shikijs/twoslash": "^1.10.3",
30+
"@astrojs/check": "^0.8.2",
31+
"@shikijs/transformers": "^1.11.0",
32+
"@shikijs/twoslash": "^1.11.0",
3333
"@total-typescript/ts-reset": "^0.5.1",
34-
"@types/node": "^20.14.10",
34+
"@types/node": "^20.14.11",
3535
"typescript": "^5.5.3"
3636
}
3737
}

examples/astro/astro.config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import {
2+
rehypePrettyCode,
3+
type RehypePrettyCodeOptions,
4+
} from 'rehype-pretty-code';
15
import mdx from '@astrojs/mdx';
6+
import type { RawTheme } from 'shiki';
27
import tailwind from '@astrojs/tailwind';
38
import { defineConfig } from 'astro/config';
4-
import { rehypePrettyCode } from 'rehype-pretty-code';
59
import moonlightTheme from './public/theme/moonlight-ii.json';
610
import { transformerCopyButton } from '@rehype-pretty/transformers';
711

@@ -12,14 +16,14 @@ export default defineConfig({
1216
[
1317
rehypePrettyCode,
1418
{
15-
theme: moonlightTheme,
19+
theme: moonlightTheme as unknown as RawTheme,
1620
transformers: [
1721
transformerCopyButton({
1822
visibility: 'hover',
1923
feedbackDuration: 2_500,
2024
}),
2125
],
22-
},
26+
} satisfies RehypePrettyCodeOptions,
2327
],
2428
],
2529
},

examples/astro/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
"clean": "rm -rf dist"
1313
},
1414
"dependencies": {
15-
"@astrojs/mdx": "^3.1.2",
15+
"@astrojs/mdx": "^3.1.3",
1616
"@astrojs/tailwind": "^5.1.0",
1717
"@rehype-pretty/transformers": "workspace:*",
18-
"astro": "^4.11.5",
18+
"astro": "^4.12.2",
1919
"rehype-pretty-code": "workspace:*",
20-
"shiki": "^1.10.3",
21-
"tailwindcss": "^3.4.5"
20+
"shiki": "^1.11.0",
21+
"tailwindcss": "^3.4.6"
2222
},
2323
"devDependencies": {
24-
"@astrojs/check": "^0.8.1",
25-
"@types/node": "^20.14.10",
24+
"@astrojs/check": "^0.8.2",
25+
"@types/node": "^20.14.11",
2626
"typescript": "^5.5.3"
2727
}
2828
}

examples/next/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node-options="--no-warnings NODE_NO_WARNINGS=1"

examples/next/next.config.mjs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Object.assign(process.env, { NEXT_TELEMETRY_DISABLED: '1' });
77
*/
88
import nextMDX from '@next/mdx';
99
import rehypeSlug from 'rehype-slug';
10-
import rehypePrettyCode from 'rehype-pretty-code';
10+
import { rehypePrettyCode } from 'rehype-pretty-code';
11+
import { transformerCopyButton } from '@rehype-pretty/transformers';
1112
import moonlightTheme from './assets/moonlight-ii.json' with { type: 'json' };
1213

1314
/** @type {NextConfigPlugins} */
@@ -19,16 +20,28 @@ const nextConfig = {
1920
cleanDistDir: true,
2021
reactStrictMode: true,
2122
poweredByHeader: false,
23+
experimental: {
24+
reactCompiler: true,
25+
useLightningcss: false, // lightningcss doesn't work with postcss-loader
26+
},
2227
pageExtensions: ['md', 'mdx', 'tsx', 'ts', 'jsx', 'js'],
2328
env: {
2429
NEXT_TELEMETRY_DISABLED: '1',
2530
},
2631
};
2732

28-
/** @type {import('rehype-pretty-code').Options} */
33+
/** @satisfies {import('rehype-pretty-code').RehypePrettyCodeOptions} */
2934
const options = {
3035
keepBackground: false,
36+
// @ts-expect-error
3137
theme: moonlightTheme,
38+
transformers: [
39+
transformerCopyButton({
40+
jsx: true,
41+
visibility: 'always',
42+
feedbackDuration: 2_500,
43+
}),
44+
],
3245
};
3346

3447
plugins.push(

examples/next/package.json

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,38 @@
22
"name": "example-next",
33
"version": "0.0.0",
44
"private": true,
5+
"type": "module",
56
"scripts": {
6-
"dev": "next dev",
7+
"dev": "bun --bun next dev",
78
"build": "next build",
89
"start": "pnpm dlx serve@latest out",
910
"clean": "rm -rf .next out"
1011
},
1112
"dependencies": {
1213
"@mdx-js/loader": "^3.0.1",
1314
"@mdx-js/react": "^3.0.1",
14-
"@next/mdx": "^14.2.5",
15+
"@next/mdx": "15.0.0-canary.68",
1516
"@rehype-pretty/transformers": "workspace:*",
1617
"@tailwindcss/typography": "^0.5.13",
1718
"autoprefixer": "^10.4.19",
18-
"next": "^14.2.5",
19+
"next": "15.0.0-canary.76",
1920
"postcss": "^8.4.39",
20-
"react": "^18.3.1",
21-
"react-dom": "^18.3.1",
21+
"react": "19.0.0-rc.0",
22+
"react-dom": "19.0.0-rc.0",
2223
"rehype-pretty-code": "workspace:*",
2324
"rehype-slug": "^6.0.0",
2425
"rehype-stringify": "^10.0.0",
25-
"shiki": "^1.10.3",
26-
"tailwindcss": "^3.4.5"
26+
"shiki": "^1.11.0",
27+
"tailwindcss": "^3.4.6"
2728
},
2829
"devDependencies": {
2930
"@types/mdx": "^2.0.13",
30-
"@types/node": "^20.14.10",
31+
"@types/node": "^20.14.11",
32+
"@types/postcss-import": "^14.0.3",
3133
"@types/react": "^18.3.3",
3234
"@types/react-dom": "^18.3.0",
35+
"babel-plugin-react-compiler": "0.0.0-experimental-696af53-20240625",
36+
"postcss-import": "^16.1.0",
3337
"typescript": "^5.5.3"
3438
},
3539
"browserslist": [

examples/next/postcss.config.cjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** @type {import('postcss-load-config').Config} */
2+
module.exports = {
3+
plugins: {
4+
tailwindcss: { config: './tailwind.config.ts' },
5+
autoprefixer: {},
6+
},
7+
};

examples/next/postcss.config.js

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

examples/next/src/app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function RootLayout({
1212
children: React.ReactNode;
1313
}) {
1414
return (
15-
<html lang="en">
15+
<html lang="en" suppressHydrationWarning={true}>
1616
<body>{children}</body>
1717
</html>
1818
);

0 commit comments

Comments
 (0)