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

0.5.1 • Public • Published

@temelj/mdx-react


Helpers for rendering MDX with React.

Created by Tin Rabzelj jsr License

jsr   •   npm   •   Issues   •   @tinrab


Installation

# npm
$ npm install @temelj/mdx-react
# jsr
$ deno add jsr:@temelj/mdx-react # or jsr add @temelj/mdx-react

Usage

To render the MDX artifact, you call the createMdxContent function. It will evaluate the compiled "function body" and return a React node. You can also override components with your custom ones.

import { createMdxContent, MdxCompiler } from "@temelj/mdx";

const compiler = new MdxCompiler();
const page = await compiler.compile(source, {
  mdxOptions: {
    // This is always 'function-body'.
    // outputFormat: "function-body",
    // Or 'undefined' if rendering server-side as a RSC.
    providerImportSource: "@mdx-js/react",
  },
});

const node = createMdxContent({ artifact: page }, mdxPageComponents);

const rendered = <div>{node}</div>;

You will also need to include a CSS file. You can find an example in ./examples/mdx-react/basic.

Readme

Keywords

Package Sidebar

Install

npm i @temelj/mdx-react

Weekly Downloads

77

Version

0.5.1

License

MIT

Unpacked Size

8.18 kB

Total Files

13

Last publish

Collaborators

  • tinrab