Skip to content

Commit 78eb453

Browse files
committed
re-add meta mdx logic
1 parent 521e058 commit 78eb453

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/components/MDX/Sandpack/createFileMap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const createFileMap = (codeSnippets: any) => {
2626
>;
2727
}>
2828
).children;
29+
2930
let filePath; // path in the folder structure
3031
let fileHidden = false; // if the file is available as a tab
3132
let fileActive = false; // if the file tab is shown by default

src/utils/compileMDX.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import remarkGfm from 'remark-gfm';
88
import remarkFrontmatter from 'remark-frontmatter';
99
import {prepareMDX} from './prepareMDX'; // Assuming prepareMDX is modularized
1010
import {MDXComponents} from '../components/MDX/MDXComponents'; // Assuming MDXComponents is modularized
11+
import visit from 'unist-util-visit';
1112

1213
const DISK_CACHE_BREAKER = 11;
1314

@@ -46,6 +47,25 @@ export default async function compileMDX(
4647
const code = String(
4748
await compile(mdx, {
4849
remarkPlugins: [...remarkPlugins, remarkGfm, remarkFrontmatter],
50+
51+
rehypePlugins: [
52+
// Support stuff like ```js App.js {1-5} active by passing it through.
53+
function rehypeMetaAsAttributes() {
54+
return (tree) => {
55+
visit(tree, 'element', (node) => {
56+
if (
57+
// @ts-expect-error -- tagName is a valid property
58+
node.tagName === 'code' &&
59+
node.data &&
60+
node.data.meta
61+
) {
62+
// @ts-expect-error -- properties is a valid property
63+
node.properties.meta = node.data.meta;
64+
}
65+
});
66+
};
67+
},
68+
],
4969
outputFormat: 'function-body',
5070
})
5171
);

0 commit comments

Comments
 (0)