Nimble Polyglot Microcosm
Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

parse-md

1.0.3 • Public • Published

parseMD

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 for that.

What It Does

For example,

---
title: This is a test
description: Once upon a time...
---
# Title of my great post
Lorem ipsum dolor...

would be parsed as

{
  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

Node/CommonJS

First, install it via NPM and save it to your project:

$ npm install parse-md --save

Import it where you need it:

import parseMD from 'parse-md';

or if you are using < ES2015,

var parseMD = require('parse-md');

and then pass it a Markdown file's content. Here is one method by which you might do so:

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..."

Contribute

  1. Check out the issues
  2. Fork this repository
  3. Clone your fork
  4. Check out a feature branch ($ git checkout -b my-feature)
  5. Make your changes and push your branch to your GitHub repo
  6. Create a pull request from your branch to this repo's master
  7. When all is merged, pull down the upstream changes to your master

install

npm i parse-md

Downloadsweekly downloads

30

version

1.0.3

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability