Skip to content

eslint-markdown-parser ​

A blazing fast Markdown parser for ESLint.

eslint-markdown-parser parses Markdown source text into an mdast syntax tree. It supports CommonMark and GitHub Flavored Markdown (GFM), with optional support for YAML, TOML, or JSON front matter and math syntax.

Installation ​

Prerequisites ​

  • Node.js: ^20.19.0 || ^22.13.0 || >=24.0.0
  • Module Support: ECMAScript Modules (ESM) Only

Install ​

sh
npm install -D eslint-markdown-parser
sh
pnpm add -D eslint-markdown-parser
sh
yarn add --dev eslint-markdown-parser
sh
bun add -d eslint-markdown-parser

Usage ​

The default export provides the parser metadata and the parse function. The same values are also available as named exports.

js
import parser from 'eslint-markdown-parser';

const ast = parser.parse('# Hello, world!', {
  mode: 'gfm',
  frontmatter: 'yaml',
  math: true,
});

Configuration ​

Pass parser options as the second argument to parse:

ts
interface ParseOptions {
  mode?: 'commonmark' | 'gfm';
  frontmatter?: false | 'yaml' | 'toml' | 'json';
  math?: boolean;
}

mode ​

Default: 'commonmark'

Controls the Markdown dialect. Use 'commonmark' for CommonMark or 'gfm' for GitHub Flavored Markdown.

frontmatter ​

Default: false

Controls front matter parsing. Use false to disable front matter, 'yaml' or 'json' for front matter delimited by ---, or 'toml' for front matter delimited by +++.

math ​

Default: false

Enables inline and block math syntax when set to true.

Exports ​

NameDescription
defaultParser object containing meta and parse.
metaObject containing the package name and version.
parseFunction that parses Markdown source text into an mdast Root syntax tree.
JsonTypeScript type for JSON front matter nodes.
JsonDataTypeScript type for data associated with JSON front matter nodes.
ParseOptionsTypeScript type for the options accepted by parse.

Package metadata is also available through the eslint-markdown-parser/package.json subpath export.