# @mdit-vue/plugin-frontmatter

> A markdown-it plugin to get markdown frontmatter

Latest version **3.0.2** (published 2025-08-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mdit-vue/plugin-frontmatter
pnpm add @mdit-vue/plugin-frontmatter
yarn add @mdit-vue/plugin-frontmatter
bun add @mdit-vue/plugin-frontmatter
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2025-08-11 |
| First published | 2022-07-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20.0.0 |
| Dependencies | 4 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 220 |
| Author | meteorlxy |
| Maintainers | meteorlxy |
| Keywords | markdown-it, markdown-it-plugin, vue, frontmatter, excerpt |

## Links

- npm: https://www.npmjs.com/package/@mdit-vue/plugin-frontmatter
- Repository: https://github.com/mdit-vue/mdit-vue
- Homepage: https://github.com/mdit-vue
- Issues: https://github.com/mdit-vue/mdit-vue/issues
- npm.io page: https://npm.io/package/@mdit-vue/plugin-frontmatter

## Dependencies (4)

- [gray-matter](https://npm.io/package/gray-matter.md) ^4.0.3
- [markdown-it](https://npm.io/package/markdown-it.md) ^14.1.0
- [@mdit-vue/types](https://npm.io/package/@mdit-vue/types.md) 3.0.2
- [@types/markdown-it](https://npm.io/package/@types/markdown-it.md) ^14.1.2

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 3.0.2 (latest) — 2025-08-11
- 3.0.1 — 2025-08-11
- 3.0.0 — 2025-08-11
- 2.1.4 — 2025-04-10
- 2.1.3 — 2024-05-13
- 2.1.2 — 2024-04-15
- 2.1.0 — 2024-04-08
- 2.0.0 — 2023-12-08
- 1.0.0 — 2023-09-26
- 0.12.1 — 2023-08-24
- 0.12.0 — 2023-02-10
- 0.11.1 — 2022-08-30
- 0.11.0 — 2022-08-25
- 0.10.0 — 2022-08-23
- 0.9.2 — 2022-08-18
- … 7 more at https://npm.io/package/@mdit-vue/plugin-frontmatter/versions

## README

# @mdit-vue/plugin-frontmatter

[![npm](https://badgen.net/npm/v/@mdit-vue/plugin-frontmatter)](https://www.npmjs.com/package/@mdit-vue/plugin-frontmatter)
[![license](https://badgen.net/github/license/mdit-vue/mdit-vue)](https://github.com/mdit-vue/mdit-vue/blob/main/LICENSE)

A [markdown-it](https://github.com/markdown-it/markdown-it) plugin to get markdown frontmatter with [gray-matter](https://github.com/jonschlinkert/gray-matter).

- Extracts frontmatter into markdown-it `env.frontmatter`.
- Allows providing default frontmatter via markdown-it `env.frontmatter`.
- Extracts markdown content without frontmatter into markdown-it `env.content`.
- Supports extracting rendered excerpt into markdown-it `env.excerpt`.

## Install

```sh
npm i @mdit-vue/plugin-frontmatter
```

## Usage

```ts
import { frontmatterPlugin } from '@mdit-vue/plugin-frontmatter';
import type { MarkdownItEnv } from '@mdit-vue/types';
import MarkdownIt from 'markdown-it';

const md = MarkdownIt({ html: true }).use(frontmatterPlugin, {
  // options
  grayMatterOptions: {
    excerpt: true,
    excerpt_separator: '<!-- more -->',
  },
});
const env: MarkdownItEnv = {};

const rendered = md.render(
  `\
---
title: foobar
---

Everything above **more** comment will be extracted as excerpt.

<!-- more -->

Things below **more** comment will not be included in the excerpt.
`,
  env,
);

console.log(env.frontmatter);
console.log(env.content);
console.log(env.excerpt);
```

## Options

### grayMatterOptions

- Type: `GrayMatterOptions`

- Details:

  Options of [gray-matter](https://github.com/jonschlinkert/gray-matter).

### renderExcerpt

- Type: `boolean`

- Default: `true`

  Render the [excerpt](https://github.com/jonschlinkert/gray-matter#optionsexcerpt) with markdown-it or not.

  This option will only take effects when `grayMatterOptions.excerpt` is enabled (disabled by default) or `grayMatterOptions.excerpt_separator` is set (undefined by default).

---
_Source: https://npm.io/package/@mdit-vue/plugin-frontmatter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
