3.0.0 • Published 3 years ago

markdown-yaml-metadata-parser v3.0.0

Weekly downloads
345
License
MIT
Repository
github
Last release
3 years ago

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.

3.0.0

3 years ago

2.1.2

3 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago