# npm
npm install @moneko/mdx
# yarn
yarn add @moneko/mdx
# pnpm
pnpm install @moneko/mdx
异步转换mdx
import { mdx } from "@moneko/mdx";
async function main() {
const value = `
# Hello World
This is a demo of @moneko/mdx
`;
const result = await mdx({
value,
filepath: "xxx.mdx",
jsx: false,
development: true,
});
console.log(result);
}
同步转换mdx
import { mdxSync } from "@moneko/mdx";
function main() {
const value = `
# Hello World
This is a demo of @moneko/mdx
`;
const result = mdxSync({
value,
filepath: "xxx.mdx",
jsx: false,
development: true,
});
console.log(result);
}
异步提取md中的frontmatter
import { frontmatter } from "@moneko/mdx";
async function main() {
const value = `---
title: "Sample Title"
author: "Author Name"
---
## header
> This is some content.
`;
const result = await frontmatter({
value,
filepath: "xxx.mdx",
jsx: false,
development: true,
});
console.log(result.frontmatter);
}
同步提取md中的frontmatter
import { frontmatterSync } from "@moneko/mdx";
function main() {
const value = `---
title: "Sample Title"
author: "Author Name"
---
## header
> This is some content.
`;
const result = frontmatterSync({
value,
filepath: "xxx.mdx",
jsx: false,
development: true,
});
console.log(result.frontmatter);
}
import { mdx } from "@moneko/mdx";
async function main() {
const value = `
# Hello World
This is a demo of @moneko/mdx
`;
const result = await mdx({
value,
filepath: "xxx.mdx",
jsx: false,
development: true,
jsxImportSource: 'preact',
providerImportSource: '@mdx/preact'
});
console.log(result);
}
interface MdxOptions {
value: string
filepath?: string
development: boolean
providerImportSource?: string
jsx?: boolean
jsxRuntime?: string
jsxImportSource?: string
pragma?: string
pragmaFrag?: string
pragmaImportSource?: string
}
Thanks to mdxjs-rs, the awesome Rust library authored by wooorm.
Also, thanks to napi-rs, authored by Brooooooklyn, which is a great solution to help us build Node.js binding for Rust.