Socket
Socket
Sign inDemoInstall

markdown-yaml-metadata-parser

Package Overview
Dependencies
5
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    markdown-yaml-metadata-parser

Parse YAML metadata (front matter) in a markdown document


Version published
Weekly downloads
2.2K
decreased by-3.28%
Maintainers
1
Install size
771 kB
Created
Weekly downloads
 

Readme

Source

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.

Keywords

FAQs

Last updated on 29 Dec 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc