Skip to content

Commit 8d74f4e

Browse files
committed
chore: add custom rehype plugins + add providerImportSource to use @mdx-js/react
1 parent ede51b9 commit 8d74f4e

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

website/rehype-plugins.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { visit } from 'unist-util-visit';
2+
3+
export const preProcess = () => (tree) => {
4+
visit(tree, (node) => {
5+
if (node?.type === 'element' && node?.tagName === 'pre') {
6+
const [codeEl] = node.children;
7+
8+
if (codeEl.tagName !== 'code') return;
9+
10+
node.raw = codeEl.children?.[0].value;
11+
}
12+
});
13+
};
14+
15+
export const postProcess = () => (tree) => {
16+
visit(tree, 'element', (node) => {
17+
if (node?.type === 'element' && node?.tagName === 'pre') {
18+
node.properties['raw'] = node.raw;
19+
// console.log(node) here to see if you're getting the raw text
20+
}
21+
});
22+
};

website/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"**/.server/**/*.tsx",
77
"**/.client/**/*.ts",
88
"**/.client/**/*.tsx"
9-
],
9+
, "app/components/mdx/index.jsx" ],
1010
"compilerOptions": {
1111
"lib": ["DOM", "DOM.Iterable", "ES2022"],
1212
"types": ["@remix-run/node", "vite/client"],

website/vite.config.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { vercelPreset } from '@vercel/remix/vite';
99
import mdx from '@mdx-js/rollup';
1010
import rehypePrettyCode, { type Options } from 'rehype-pretty-code';
1111
import remarkGfm from 'remark-gfm';
12+
import { postProcess, preProcess } from './rehype-plugins';
1213

1314
// Rehype Pretty Options:
1415
const options = {
@@ -18,8 +19,9 @@ const options = {
1819
export default defineConfig({
1920
plugins: [
2021
mdx({
22+
providerImportSource: '@mdx-js/react',
2123
remarkPlugins: [remarkGfm],
22-
rehypePlugins: [[rehypePrettyCode, options]],
24+
rehypePlugins: [[rehypePrettyCode, options], preProcess, postProcess],
2325
}),
2426
remix({
2527
presets: [vercelPreset()],

0 commit comments

Comments
 (0)