1.0.10 • Published 4 years ago

@stefanprobst/next-markdown v1.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

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" />
1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago