Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/remarkjs/remark/llms.txt

Use this file to discover all available pages before exploring further.

remark-parse is a unified plugin that teaches a processor how to take a markdown string as input and produce an mdast syntax tree. It is the parse half of the remark ecosystem. Internally it delegates to mdast-util-from-markdown, which itself is powered by micromark — a small, safe, and CommonMark-compliant markdown parser. Other plugins can extend the parser by registering micromark and mdast extensions through the processor’s data store.

Installation

npm install remark-parse
This package is ESM only and requires Node.js 16 or later.

API

unified().use(remarkParse)

Adds support for parsing markdown into an mdast syntax tree. This sets processor.parser so that any subsequent call to .process() or .parse() on the processor will accept a markdown string as input. Import: import remarkParse from 'remark-parse'
Parameters: None — the plugin takes no configuration options.
Returns: undefined. The plugin mutates the processor by assigning its parser.
TypeScript type: Plugin<[(Readonly<Options> | null | undefined)?], string, Root>

Options

The Options type is exported for TypeScript consumers. It is currently empty (all fields are inherited from mdast-util-from-markdown except the internal extensions and mdastExtensions fields, which are managed by the plugin itself). Passing an options object is accepted but has no effect today; the type exists to allow forward-compatible extensions.
import type {Options} from 'remark-parse'

Processor data keys

Other plugins that extend the markdown syntax register their contributions through the unified processor’s data store rather than through remark-parse options directly. remark-parse reads two keys:
micromarkExtensions
Array<MicromarkExtension>
An array of micromark extensions to use when tokenising the input string. Plugins such as remark-gfm push into this array via processor.data('micromarkExtensions', [...]).
fromMarkdownExtensions
Array<FromMarkdownExtension | Array<FromMarkdownExtension>>
An array of mdast-util-from-markdown extensions that translate micromark tokens into mdast nodes. Plugins push into this array via processor.data('fromMarkdownExtensions', [...]).

Examples

Parsing markdown to HTML

This is the most common use of remark-parse — converting markdown to HTML by routing the mdast tree through rehype:
import rehypeStringify from 'rehype-stringify'
import remarkGfm from 'remark-gfm'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import {unified} from 'unified'

const value = `
# Mercury

**Mercury** is the first planet from the [Sun](https://en.wikipedia.org/wiki/Sun).
`

const file = await unified()
  .use(remarkParse)
  .use(remarkGfm)
  .use(remarkRehype)
  .use(rehypeStringify)
  .process(value)

console.log(String(file))

Supporting GFM and frontmatter

CommonMark is the only syntax supported by default. Non-standard extensions are opt-in via plugins. The following example adds GitHub Flavored Markdown (GFM) and YAML frontmatter parsing:
import rehypeStringify from 'rehype-stringify'
import remarkFrontmatter from 'remark-frontmatter'
import remarkGfm from 'remark-gfm'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import {unified} from 'unified'

const doc = `---
layout: solar-system
---

# Hi ~~Mars~~Venus!
`

const file = await unified()
  .use(remarkParse)
  .use(remarkFrontmatter)
  .use(remarkGfm)
  .use(remarkRehype)
  .use(rehypeStringify)
  .process(doc)

console.log(String(file))
// => <h1>Hi <del>Mars</del>Venus!</h1>

Turning markdown into a man page

Man pages use a legacy markup format called roff. The remark-man plugin serializes an mdast tree into roff, which means remark-parse can be paired with it directly — no HTML step required:
import remarkMan from 'remark-man'
import remarkParse from 'remark-parse'
import {unified} from 'unified'

const doc = `
# titan(7) -- largest moon of saturn

Titan is the largest moon…
`

const file = await unified().use(remarkParse).use(remarkMan).process(doc)
console.log(String(file))
When both the input and output of your pipeline are markdown, use the remark package instead of combining unified + remark-parse + remark-stringify manually. remark is a shortcut that sets up all three for you.

Syntax

Markdown is parsed according to CommonMark. Other plugins can add support for syntax extensions. If you are building a micromark extension, see micromark’s extension documentation for details on how the extension API works.

Syntax tree

The syntax tree produced by remark-parse is mdast. Each node conforms to the mdast specification, meaning downstream plugins and transformers receive a well-defined, typed tree.

TypeScript

This package is fully typed with TypeScript. It exports the additional type Options. It also augments the unified Data interface to declare micromarkExtensions and fromMarkdownExtensions, giving type safety to plugins that push into those arrays.

Compatibility

remark-parse@11 is compatible with Node.js 16 and later. The package is ESM only.

Build docs developers (and LLMs) love