@mdit-vue/plugin-frontmatter
A markdown-it plugin to get markdown frontmatter with gray-matter.
- Extract frontmatter into markdown-it
env.frontmatter
. - Allow providing default frontmatter via markdown-it
env.frontmatter
. - Support extracting rendered excerpt into markdown-it
env.excerpt
.
Install
npm i @mdit-vue/plugin-frontmatter
Usage
import MarkdownIt from 'markdown-it';
import { frontmatterPlugin } from '@mdit-vue/plugin-frontmatter';
const md = MarkdownIt({ html: true }).use(frontmatterPlugin, {
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 -->
`,
env,
);
console.log(env.frontmatter);
console.log(env.excerpt);
Options
grayMatterOptions
-
Type: GrayMatterOptions
-
Details:
Options of gray-matter.
renderExcerpt
-
Type: boolean
-
Default: true
Render the excerpt 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).