@stefanprobst/next-markdown
TypeScript icon, indicating that this package has built-in type declarations

1.0.10 • Public • Published

next-markdown

Adds a Webpack loader for importing .md files as HTML to the Next.js config.

How to use

First, add the loader to the Next.js configuration in next.config.js:

const withMarkdown = require('@stefanprobst/next-markdown')(/* options */)

const nextConfig = {
  /** ... */
}

module.exports = withMarkdown(nextConfig)

Markdown files can then be imported as HTML. Frontmatter data is accessible on the named data export:

import html, { data } from '@/content/faq.md'

export default function Page() {
  return (
    <main>
      <h1>{data.title}</h1>
      <div dangerouslySetInnerHTML={{ __html: html }}>
    </main>
  )
}

Options

See markdown-loader for options to enable parsing inline HTML.

Typescript

To make typescript understand .md imports, add the following to next-env.d.ts:

/// <reference types="@stefanprobst/next-markdown" />

Readme

Keywords

none

Package Sidebar

Install

npm i @stefanprobst/next-markdown

Weekly Downloads

0

Version

1.0.10

License

MIT

Unpacked Size

4.65 kB

Total Files

5

Last publish

Collaborators

  • stefanprobst