@moneko/mdx
TypeScript icon, indicating that this package has built-in type declarations

0.1.30 • Public • Published

@moneko/mdx

Install

# npm
npm install @moneko/mdx
# yarn
yarn add @moneko/mdx
# pnpm
pnpm install @moneko/mdx

Usage

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);
}

mdxSync

同步转换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);
}

frontmatter

异步提取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);
}

frontmatterSync

同步提取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);
}

jsxImportSource

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);
}

MdxOptions

interface MdxOptions {
  value: string
  filepath?: string
  development: boolean
  providerImportSource?: string
  jsx?: boolean
  jsxRuntime?: string
  jsxImportSource?: string
  pragma?: string
  pragmaFrag?: string
  pragmaImportSource?: string
}

Credits

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @moneko/mdx

Weekly Downloads

466

Version

0.1.30

License

MIT

Unpacked Size

17.6 kB

Total Files

5

Last publish

Collaborators

  • moneko