markdown-yaml-metadata-parser

3.0.0 • Public • Published

Markdown YAML metadata parser

Build Status

Parse YAML metadata (front matter) in a markdown document.

This is a dual module, written in ESM (ECMAScript modules) and supporting CJS (CommonJS).

Installation

Install the latest version via npm:

$ npm install markdown-yaml-metadata-parser

Usage

In order to be parsed, metadata must be placed at the beginning of the markdown document between two triple dashes (YAML front matter). Example:

---
title: Meditations
author: Marcus Aurelius
keywords: stoicism, book
---

Vestibulum tortor quam, *feugiat vitae*, ultricies eget, tempor sit amet, ante.

Here's how to parse the metadata. Import (or require) the parser:

import metadataParser from 'markdown-yaml-metadata-parser'

Assuming source is a string containing the markdown document, parse source:

const source = '--- title: Meditations...'
const result = metadataParser(source)

result is a two-property object. The first property, result.metadata, is the object of parsed metadata:

{
  'title': 'Meditations',
  'author': 'Marcus Aurelius',
  'keywords': 'stoicism, book'
}

The second property, result.content, is the document source without metadata:

Vestibulum tortor quam, *feugiat vitae*, ultricies eget, tempor sit amet, ante.

License

Markdown YAML metadata parser is licensed under the MIT License. See the LICENSE file for details.

Package Sidebar

Install

npm i markdown-yaml-metadata-parser

Weekly Downloads

2,261

Version

3.0.0

License

MIT

Unpacked Size

22.7 kB

Total Files

10

Last publish

Collaborators

  • ilterra