A robust Next.js newsletter Next.js Weekly is sponsoring me π

A warm thanks π to @ErfanEbrahimnia, @recepkyk, and @LSeaburg for the support π
This package is an opinionated wrapper of next-mdx-remote-client. Since it is peer dependent to next-mdx-remote-client you need to install next-mdx-remote-client as well.
@ipikuka/mdx is battery-included. You don't need to add any remark, rehype, remark plugins because I included them already according to my expertise. If you need to add a plugin let me know opening an issue.
The plugins used in @ipikuka/mdx comes from @ipikuka/plugins which provides remarkPlugins, rehypePlugins, recmaPlugins.
The rehype handlers used in @ipikuka/mdx comes from @ipikuka/handlers which provides remarkRehypeOptions["handlers"].
Thanks to @ipikuka/plugins and @ipikuka/handlers, markdown/MDX content will support:
- bold texts, italic texts,
- lists, blockquotes, headings,
- table of contents (TOC),
- containers, admonitions, callouts,
- marked texts, inserted texts,
- centered paragraphs, aligned paragraphs,
- guillements,
- gfm syntax (tables, strikethrough, task lists, autolinks, footnotes etc.),
- highlighted and numbered code fences,
- code titles,
- autolink for headers,
- abbreviations,
- inline footnotes,
- enhanced markdown image syntax,
- definition lists etc. and many more.
This package is suitable for ESM module only. In Node.js (16.0+), install with npm:
npm install @ipikuka/mdx next-mdx-remote-client
# if you are using react@19 specifically
npm install @ipikuka/mdx next-mdx-remote-client@2
# if you are using react@18 specifically
npm install @ipikuka/mdx next-mdx-remote-client@1or
yarn add @ipikuka/mdx next-mdx-remote-client
# if you are using react@19 specifically
yarn add @ipikuka/mdx next-mdx-remote-client@2
# if you are using react@18 specifically
yarn add @ipikuka/mdx next-mdx-remote-client@1This package is peer dependant with react, react-dom and next-mdx-remote-client so it is assumed that you have already installed them.
@ipikuka/mdx provides a serialize function. The serialize function is an opinionated wrapper of the serialize function of the next-mdx-remote-client which is a set of light utilities allowing MDX to be loaded within getStaticProps or gerServerSideProps and hydrated correctly on the client.
@ipikuka/mdx provides also hydrate function and MDXClient component for "pages" router.
See for more details about next-mdx-remote-client.
import { serialize } from "@ipikuka/mdx/serialize";
import { MDXClient } from "@ipikuka/mdx";
import ErrorComponent from "../components/ErrorComponent";
import { TableOfComponent, Test } from "../mdxComponents";
const components = {
TableOfComponent,
Test,
wrapper: ({ children }) => <div className="mdx-wrapper">{children}</div>,
};
export default function Page({ mdxSource }) {
if ("error" in mdxSource) {
return <ErrorComponent error={mdxSource.error} />;
}
return <MDXClient {...mdxSource} components={components} />;
}
export async function getStaticProps() {
const source = `---
title: My Article
---
<TableOfComponent toc={toc} />
Some **bold** and ==marked== text in MDX.
~|> Centered paragraph (thanks to remark-flexible-paragraphs)
With a component <Test />
::: tip The Title of The Container
The content of the tip (thanks to remark-flexible-containers)
:::
`;
const mdxSource = await serialize({
source,
options: { parseFrontmatter: true },
});
return { props: { mdxSource } };
}The @ipikuka/mdx provides evaluate function and MDXRemote component for "app" router.
See for more details about next-mdx-remote-client.
import { Suspense } from "react";
import { MDXRemote } from "@ipikuka/mdx/rsc";
import { ErrorComponent, LoadingComponent } from "../components";
import { TableOfComponent, Test } from "../mdxComponents";
const components = {
TableOfComponent,
Test,
wrapper: ({ children }) => <div className="mdx-wrapper">{children}</div>,
};
export default async function Page() {
const source = `---
title: My Article
---
<TableOfComponent toc={toc} />
Some **bold** and ==marked== text in MDX.
~|> Centered paragraph (thanks to remark-flexible-paragraphs)
With a component <Test />
::: tip The Title of The Container
The content of the tip (thanks to remark-flexible-containers)
:::
`;
return (
<Suspense fallback={<LoadingComponent />}>
<MDXRemote
source={source}
options={{ parseFrontmatter: true }}
components={components}
onError={ErrorComponent}
/>
</Suspense>
);
}@ipikuka/mdx has the same options with next-mdx-remote-client as a wrapper.
@ipikuka/mdx is fully typed with TypeScript and exposes the same types as next-mdx-remote-client does.
It is a Nextjs compatible package.
This package has the same security concerns with next-mdx-remote-client.
I like to contribute the Unified / Remark / MDX ecosystem, so I recommend you to have a look my plugins.
Support My Work (become a sponsor π)
If you find @ipikuka/plugins or any of my projects is useful and helpful, please consider supporting my work. Your sponsorship means a lot to me and keeps these projects alive and updated! π
My sponsors are going to be featured at the very top of the page and proudly displayed on my Sponsor Wall.
Thank you for supporting open source! π
remark-flexible-code-titlesβ Remark plugin to add titles or/and containers for the code blocks with customizable propertiesremark-flexible-containersβ Remark plugin to add custom containers with customizable properties in markdownremark-insβ Remark plugin to addinselement in markdownremark-flexible-paragraphsβ Remark plugin to add custom paragraphs with customizable properties in markdownremark-flexible-markersβ Remark plugin to add custommarkelement with customizable properties in markdownremark-flexible-tocβ Remark plugin to expose the table of contents viavfile.dataor via an option referenceremark-mdx-remove-esmβ Remark plugin to remove import and/or export statements (mdxjsEsm)remark-mdx-remove-expressionsβ Remark plugin to remove MDX expressions within curlybraces {} in MDX content
rehype-pre-languageβ Rehype plugin to add language information as a property topreelementrehype-highlight-code-linesβ Rehype plugin to add line numbers to code blocks and allow highlighting of desired code linesrehype-code-metaβ Rehype plugin to copycode.data.metatocode.properties.metastringrehype-image-toolkitβ Rehype plugin to enhance Markdown image syntax![]()and Markdown/MDX media elements (<img>,<audio>,<video>) by auto-linking bracketed or parenthesized image URLs, wrapping them in<figure>with optional captions, unwrapping images/videos/audio from paragraph, parsing directives in title for styling and adding attributes, and dynamically converting images into<video>or<audio>elements based on file extension.
recma-mdx-escape-missing-componentsβ Recma plugin to set the default value() => nullfor the Components in MDX in case of missing or not provided so as not to throw an errorrecma-mdx-change-propsβ Recma plugin to change thepropsparameter into the_propsin thefunction _createMdxContent(props) {/* */}in the compiled source in order to be able to use{props.foo}like expressions. It is useful for thenext-mdx-remoteornext-mdx-remote-clientusers innextjsapplications.recma-mdx-change-importsβ Recma plugin to convert import declarations for assets and media with relative links into variable declarations with string URLs, enabling direct asset URL resolution in compiled MDX.recma-mdx-import-mediaβ Recma plugin to turn media relative paths into import declarations for both markdown and html syntax in MDX.recma-mdx-import-reactβ Recma plugin to ensure gettingReactinstance from the arguments and to make the runtime props{React, jsx, jsxs, jsxDev, Fragment}is available in the dynamically imported components in the compiled source of MDX.recma-mdx-html-overrideβ Recma plugin to allow selected raw HTML elements to be overridden via MDX components.recma-mdx-interpolateβ Recma plugin to enable interpolation of identifiers wrapped in curly braces within thealt,src,href, andtitleattributes of markdown link and image syntax in MDX.
I also build low-level utilities and plugins for the Unified ecosystem that can be used across Remark, Rehype, Recma, and other unist-based abstract syntax trees (ASTs).
unist-util-find-betweenβ Unist utility to find the nodes between two nodes.unified-log-treeβ Unified plugin to log abstract syntax trees (ASTs) for debugging without mutating.
MIT License Β© ipikuka