2.0.0 • Published 7 days ago

@ipikuka/next-mdx-remote v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 days ago

@ipikuka/next-mdx-remote

NPM version Build npm-typescriptLicense]github-license-url

This package is an opinionated wrapper of the next-mdx-remote.

When should I use this?

The @ipikuka/next-mdx-remote provides a serialize function. The serialize function is an opinionated wrapper of the serialize function of the next-mdx-remote which is a set of light utilities allowing MDX to be loaded within getStaticProps or gerServerSideProps and hydrated correctly on the client.

The plugins used in the @ipikuka/next-mdx-remote comes from @ipikuka/plugins.

@ipikuka/plugins provides remarkPlugins, rehypePlugins, recmaPlugins, and remarkRehypeOptions.

Thanks to @ipikuka/plugins, the markdown/mdx content will support table of contents, containers, markers, aligned paragraphs, gfm syntax (tables, strikethrough, task lists, autolinks etc.), inserted texts, highlighted code fences, code titles, autolink for headers, definition lists etc. in addition to standard markdown syntax like bold texts, italic texts, lists, blockquotes, headings etc.

For other mdxOptions see https://github.com/hashicorp/next-mdx-remote#apis.

Installation

This package is suitable for ESM module only. In Node.js (16.0+), install with npm:

npm install @ipikuka/next-mdx-remote

or

yarn add @ipikuka/next-mdx-remote

Usage

This package is peer dependant with react, react-dom; so it is assumed that you have already installed.

import { MDXRemote } from "@ipikuka/next-mdx-remote";
import { serialize } from "@ipikuka/next-mdx-remote/serialize";

import * as components from "../components/mdxcomponents";

export default function TestPage({ mdxSource }) {
  return (
    <div className="mdx-wrapper">
      <MDXRemote {...mdxSource} components={components} />
    </div>
  );
}

export async function getStaticProps() {
  // the source can be from a local file, database, anywhere
  const source = "Some mdx content with a component <Test />";
  const mdxSource = await serialize(source);

  return { props: { mdxSource } };
}

Options

The @ipikuka/next-mdx-remote serialize function accepts the same options with next-mdx-remote.

All options are optional.

type SerializeOptions = {
  /**
   * Pass-through variables for use in the MDX content
   */
  scope?: Record<string, unknown>;
  /**
   * These options are passed to the MDX compiler.
   * See [the MDX docs.](https://github.com/mdx-js/mdx/blob/master/packages/mdx/index.js).
   */
  mdxOptions?: Omit<CompileOptions, "outputFormat" | "providerImportSource"> & {
    useDynamicImport?: boolean;
  };
  /**
   * Indicate whether or not frontmatter should be parsed out of the MDX. Defaults to false
   */
  parseFrontmatter?: boolean;
};

For example, you can specify the source is markdown md. (Default is MDX mdx).

const source = "Some **bold text** and ==marked text==";
const mdSource = await serialize(source, { mdxOptions: { format: "md" } });

Examples:

Need a playground with single page web application. (PR is wellcome)

Types

This package is fully typed with TypeScript and exposes the types as the official next-mdx-remote does.

Compatibility

It is a Nextjs compatible package.

Security

License

MIT © ipikuka

Keywords

unified remark remark-plugin next-mdx-remote

2.0.0

7 days ago

1.0.3

4 months ago

1.0.2

11 months ago

1.0.1

1 year ago

1.0.0-beta.3

1 year ago

1.0.0-beta.2

1 year ago

1.0.0-beta.1

1 year ago

1.0.0-alpha.10

1 year ago

1.0.0-alpha.9

1 year ago

1.0.0-alpha.8

1 year ago

1.0.0-alpha.7

1 year ago

1.0.0-alpha.6

1 year ago

1.0.0-alpha.5

1 year ago

1.0.0-alpha.3

1 year ago

1.0.0-alpha.2

1 year ago

1.0.0-alpha.1

1 year ago

1.0.0-alpha.0

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.10

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago