Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rpearce/parse-md
Parse Markdown file's metadata from its content
https://github.com/rpearce/parse-md
markdown markdown-metadata markdown-parser markdown-yaml metadata parsing
Last synced: 3 months ago
JSON representation
Parse Markdown file's metadata from its content
- Host: GitHub
- URL: https://github.com/rpearce/parse-md
- Owner: rpearce
- License: mit
- Created: 2015-10-28T02:56:13.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2023-01-07T17:36:16.000Z (about 2 years ago)
- Last Synced: 2024-10-09T16:36:09.261Z (3 months ago)
- Topics: markdown, markdown-metadata, markdown-parser, markdown-yaml, metadata, parsing
- Language: TypeScript
- Homepage: https://github.com/rpearce/parse-md
- Size: 846 KB
- Stars: 39
- Watchers: 3
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- project-awesome - rpearce/parse-md - Parse Markdown file's metadata from its content (TypeScript)
README
# parseMD
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-) [![npm version](https://img.shields.io/npm/v/parse-md.svg?style=flat-square)](https://www.npmjs.com/package/parse-md) [![npm downloads](https://img.shields.io/npm/dm/parse-md.svg?style=flat-square)](https://www.npmjs.com/package/parse-md) [![bundlephobia size](https://flat.badgen.net/bundlephobia/minzip/parse-md)](https://bundlephobia.com/result?p=parse-md)
This library exists as a way to pass a markdown file's content and have its
metadata and markdown returned as an object containing `metadata` and `content`
keys.Note that it is not trying to do anything but solve the markdown metadata vs.
content parsing problem and is _not parsing the markdown body, itself._ You can
use something like [marked](https://github.com/chjj/marked) for that.## What It Does
For example,
```md
---
title: This is a test
description: Once upon a time...
---
# Title of my great post
Lorem ipsum dolor...
```would be parsed as
```js
{
metadata: {
title: "This is a test",
description: "Once upon a time..."
},
content: "# Title of my great post\nLorem ipsum dolor..."
}
```_Note: This tool expects that your Markdown metadata has `---` boundaries, as
shown above._## Usage
Installation:
```sh
npm i parse-md
```Import it where you need it, and then pass it a Markdown file's content:
```javascript
import fs from 'fs'
import parseMD from 'parse-md'const fileContents = fs.readFileSync('posts/first.md', 'utf8')
const { metadata, content } = parseMD(fileContents)console.log(metadata) // { title: 'Great first post', description: 'This is my first great post. Rawr' }
console.log(content) // "# My first post..."
```## Links
* [`Changelog`](./CHANGELOG.md)
* [`Contributing`](./CONTRIBUTING.md)
* [`Code of Conduct`](./CODE_OF_CONDUCT.md)## Note about CommonJS
If you need to CommonJS module support, use version `2.x`, and require it like
this:```javascript
const parseMD = require('parse-md').default
```## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Robert Pearce
💻 📖 💡 🤔 ⚠️
Justin Chan
🐛
Alex Gherghisan
💻 🐛 🤔
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!