Skip to content

Commit

Permalink
chore: add custom rehype plugins + add providerImportSource t…
Browse files Browse the repository at this point in the history
…o use ``@mdx-js/react``
  • Loading branch information
pheralb committed Jul 1, 2024
1 parent ede51b9 commit 8d74f4e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
22 changes: 22 additions & 0 deletions website/rehype-plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { visit } from 'unist-util-visit';

export const preProcess = () => (tree) => {
visit(tree, (node) => {
if (node?.type === 'element' && node?.tagName === 'pre') {
const [codeEl] = node.children;

if (codeEl.tagName !== 'code') return;

node.raw = codeEl.children?.[0].value;
}
});
};

export const postProcess = () => (tree) => {
visit(tree, 'element', (node) => {
if (node?.type === 'element' && node?.tagName === 'pre') {
node.properties['raw'] = node.raw;
// console.log(node) here to see if you're getting the raw text
}
});
};
2 changes: 1 addition & 1 deletion website/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"**/.server/**/*.tsx",
"**/.client/**/*.ts",
"**/.client/**/*.tsx"
],
, "app/components/mdx/index.jsx" ],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"types": ["@remix-run/node", "vite/client"],
Expand Down
4 changes: 3 additions & 1 deletion website/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { vercelPreset } from '@vercel/remix/vite';
import mdx from '@mdx-js/rollup';
import rehypePrettyCode, { type Options } from 'rehype-pretty-code';
import remarkGfm from 'remark-gfm';
import { postProcess, preProcess } from './rehype-plugins';

// Rehype Pretty Options:
const options = {
Expand All @@ -18,8 +19,9 @@ const options = {
export default defineConfig({
plugins: [
mdx({
providerImportSource: '@mdx-js/react',
remarkPlugins: [remarkGfm],
rehypePlugins: [[rehypePrettyCode, options]],
rehypePlugins: [[rehypePrettyCode, options], preProcess, postProcess],
}),
remix({
presets: [vercelPreset()],
Expand Down

0 comments on commit 8d74f4e

Please sign in to comment.