Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/phuctm97/remark-parse-frontmatter
🎓 Parses and validates Markdown frontmatter (YAML) to data object.
https://github.com/phuctm97/remark-parse-frontmatter
commonmark extension frontmatter markdown plugin remark remark-plugin unified unified-plugin yaml
Last synced: 2 months ago
JSON representation
🎓 Parses and validates Markdown frontmatter (YAML) to data object.
- Host: GitHub
- URL: https://github.com/phuctm97/remark-parse-frontmatter
- Owner: phuctm97
- License: mit
- Created: 2020-12-25T10:36:59.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-02-27T03:06:46.000Z (almost 2 years ago)
- Last Synced: 2024-11-28T18:41:27.675Z (2 months ago)
- Topics: commonmark, extension, frontmatter, markdown, plugin, remark, remark-plugin, unified, unified-plugin, yaml
- Language: TypeScript
- Homepage:
- Size: 57.6 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# 🎓 remark-parse-frontmatter
[![Github checks][checks badge]][checks url]
[![npm version][npm badge]][npm url]
[![Code style][code style badge]][code style url]
[![GitHub license][license badge]][license url]Parses and validates Markdown frontmatter (YAML) to `file.data.frontmatter`.
Validation is done by [revalidator].
Built for Remark 12, won't work with Remark 13. Requires [remark-frontmatter].
## Example
`example.js`:
```js
const processor = remark()
.use(require("remark-frontmatter"))
.use(require("remark-parse-frontmatter"))
.freeze();const file = processor.processSync(`
---
title: Hello, World!
---
`);console.log(file.data.frontmatter);
```Output:
```
{
title: "Hello, World!"
}
```## Usage
### Install
```bash
yarn add remark-parse-frontmatter
```### Configure
Unified / Remark:
```js
// Without validation
unified()
.use(require("remark-parse"))
.use(require("remark-frontmatter"))
.use(require("remark-parse-frontmatter"))
.use(require("remark-stringify"));// With validation
unified()
.use(require("remark-parse"))
.use(require("remark-frontmatter"))
.use(require("remark-parse-frontmatter"), {
properties: {
title: { type: "string", required: true },
tags: { type: "array", maxItems: 4 },
},
})
.use(require("remark-stringify"));
``````js
// Without validation.
remark()
.use(require("remark-frontmatter"))
.use(require("remark-parse-frontmatter"));// With validation.
remark()
.use(require("remark-frontmatter"))
.use(require("remark-parse-frontmatter"), {
properties: {
title: { type: "string", required: true },
tags: { type: "array", maxItems: 4 },
},
});
```MDX:
```js
// Without validation.
mdx(mdxText, {
remarkPlugins: [
require("remark-unwrap-texts"),
require("remark-parse-frontmatter"),
],
});// With validation.
mdx(mdxText, {
remarkPlugins: [
require("remark-unwrap-texts"),
[
require("remark-parse-frontmatter"),
{
properties: {
title: { type: "string", required: true },
tags: { type: "array", maxItems: 4 },
},
},
],
],
});
```---
Made by [@phuctm97].
[checks badge]:
https://img.shields.io/github/checks-status/phuctm97/remark-parse-frontmatter/master?logo=Github
[npm badge]: https://img.shields.io/npm/v/remark-parse-frontmatter?logo=npm
[code style badge]:
https://img.shields.io/badge/code%20style-prettier-F7B93E?logo=Prettier
[license badge]:
https://img.shields.io/github/license/phuctm97/remark-parse-frontmatter
[checks url]:
https://github.com/phuctm97/remark-parse-frontmatter/actions?query=workflow%3APR+branch%3Amaster
[npm url]: https://www.npmjs.com/package/remark-parse-frontmatter
[code style url]: /.prettierrc.json
[license url]: /LICENSE[@phuctm97]: https://twitter.com/phuctm97
[remark-frontmatter]: https://github.com/remarkjs/remark-frontmatter
[revalidator]: https://github.com/flatiron/revalidator