Initial commit
This commit is contained in:
commit
ae3f59765e
2 changed files with 32 additions and 0 deletions
14
index.ts
Normal file
14
index.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { evaluate } from "@mdx-js/mdx";
|
||||
import * as runtime from "react/jsx-runtime";
|
||||
import { createElement } from "react";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import type { Integration } from "muddle/contracts";
|
||||
|
||||
export async function renderMdx(source: string): Promise<string> {
|
||||
const module = await evaluate(source, { ...runtime });
|
||||
return renderToStaticMarkup(createElement(module.default));
|
||||
}
|
||||
|
||||
export function mdxIntegration(): Integration {
|
||||
return { name: "mdx", setup(context) { context.loader("mdx", { name: "mdx", extensions: [".mdx"], async load(file) { return { data: {}, content: await renderMdx(file.source) }; } }); } };
|
||||
}
|
||||
18
package.json
Normal file
18
package.json
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "@muddle/mdx",
|
||||
"type": "module",
|
||||
"exports": "./index.ts",
|
||||
"version": "0.1.0",
|
||||
"peerDependencies": {
|
||||
"muddle": "*"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mdx-js/mdx": "^3.1.1",
|
||||
"react": "^19.3.1",
|
||||
"react-dom": "^19.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^19.3.0",
|
||||
"@types/react-dom": "^19.3.0"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue