UNPKG

@ipikuka/mdx

Version:

An opinionated wrapper of `next-mdx-remote-client`

41 lines 1.29 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { evaluate as evaluate_ } from "next-mdx-remote-client/rsc"; import { plugins, prepare } from "@ipikuka/plugins"; /** * * Opinionated evaluate wrapper for "next-mdx-remote/rsc" * */ export async function evaluate({ source, options = {}, components = {}, }) { const { mdxOptions, ...rest } = options || {}; const format_ = mdxOptions?.format; const format = format_ === "md" || format_ === "mdx" ? format_ : "mdx"; const processedSource = format === "mdx" ? prepare(source) : source; return await evaluate_({ source: processedSource, options: { mdxOptions: { ...mdxOptions, ...plugins({ format }), }, vfileDataIntoScope: "toc", ...rest, }, components, }); } /** * * MDXRemote which uses opinionated wrapper evalute for "next-mdx-remote/rsc" * */ export async function MDXRemote(props) { const { onError: ErrorComponent, ...rest } = props; const { content, error } = await evaluate(rest); if (error && !ErrorComponent) throw error; if (error && ErrorComponent) return _jsx(ErrorComponent, { error: error }); return content; } //# sourceMappingURL=rsc.js.map