All Projects β†’ yuanqing β†’ Fastmatter

yuanqing / Fastmatter

Licence: mit
πŸ‘€ A fast frontmatter parser. Supports both string and stream inputs.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Fastmatter

Prettier
Prettier is an opinionated code formatter.
Stars: ✭ 41,411 (+165544%)
Mutual labels:  markdown, yaml
Grav
Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony
Stars: ✭ 13,067 (+52168%)
Mutual labels:  markdown, yaml
Gray Matter
Contributing Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Stars: ✭ 2,105 (+8320%)
Mutual labels:  markdown, yaml
Pico
Pico is a stupidly simple, blazing fast, flat file CMS.
Stars: ✭ 3,494 (+13876%)
Mutual labels:  markdown, yaml
Feedparser
feedparser gem - (universal) web feed parser and normalizer (XML w/ Atom or RSS, JSON Feed, HTML w/ Microformats e.g. h-entry/h-feed or Feed.HTML, Feed.TXT w/ YAML, JSON or INI & Markdown, etc.)
Stars: ✭ 156 (+524%)
Mutual labels:  markdown, yaml
Letter Boilerplate
Finest letter typesetting from the command line
Stars: ✭ 374 (+1396%)
Mutual labels:  markdown, yaml
Cocalc
CoCalc: Collaborative Calculation in the Cloud
Stars: ✭ 888 (+3452%)
Mutual labels:  markdown
Marked
Markdown rendering as a service.
Stars: ✭ 19 (-24%)
Mutual labels:  markdown
Silverstripe Markdowntextareafield
Supercharged textarea with markdown preview for Silverstripe CMS
Stars: ✭ 6 (-76%)
Mutual labels:  markdown
Showdown Htmlescape
Plugin for Showdown to prevent the use of arbitrary HTML and allow only the specific Markdown syntax.
Stars: ✭ 6 (-76%)
Mutual labels:  markdown
Home Assistant Config
Home Assistant config files, rewritten to use the latest features, 100+ documented automations, automatically generated ToC 🏠 πŸ€–
Stars: ✭ 926 (+3604%)
Mutual labels:  yaml
Gridsome Starter Liebling
Grisome starter based on Ghost Liebling and tailwindcss.
Stars: ✭ 23 (-8%)
Mutual labels:  markdown
Mdx linkify
Link recognition for Python Markdown
Stars: ✭ 18 (-28%)
Mutual labels:  markdown
React Markings
**Markdown** in <Components/>, <Components/> in **Markdown**
Stars: ✭ 893 (+3472%)
Mutual labels:  markdown
Jbake
Java based open source static site/blog generator for developers & designers.
Stars: ✭ 904 (+3516%)
Mutual labels:  markdown
Strictyaml
Type-safe YAML parser and validator.
Stars: ✭ 836 (+3244%)
Mutual labels:  yaml
Easy Pandoc Templates
A collection of portable pandoc templates with no dependencies
Stars: ✭ 23 (-8%)
Mutual labels:  markdown
Markdown Wasm
Markdown parser and HTML generator implemented in WebAssembly, based on md4c
Stars: ✭ 833 (+3232%)
Mutual labels:  markdown
Phd thesis markdown
Template for writing a PhD thesis in Markdown
Stars: ✭ 898 (+3492%)
Mutual labels:  markdown
Markdown2document
turn markdown files to a PDF or HTML document
Stars: ✭ 22 (-12%)
Mutual labels:  markdown

fastmatter npm Version Build Status Coverage Status

A fast frontmatter parser. Supports both string and stream inputs.

Usage

Given a document foo.md containing YAML frontmatter and content:

---
title: Hello, World!
tags: [ foo, bar, baz ]
---
Lorem ipsum dolor sit amet consectetur adipisicing elit.

…we can parse this document as a string, via fastmatter(string):

const fastmatter = require('fastmatter')
const fs = require('fs')

fs.readFile('foo.md', 'utf8', function (error, data) {
  if (error) {
    throw error
  }
  console.log(fastmatter(data))
  /* =>
   * {
   *   attributes: {
   *     title: 'Hello, World!',
   *     tags: [ 'foo', 'bar', 'baz' ]
   *   },
   *   body: 'Lorem ipsum dolor sit amet consectetur adipisicing elit.'
   * }
   */
})

…or as a stream, via fastmatter.stream([callback]):

const fastmatter = require('fastmatter')
const fs = require('fs')
const concat = require('concat-stream')

fs.createReadStream('foo.md').pipe(
  fastmatter.stream(function (attributes) {
    console.log(attributes)
    /* =>
     * {
     *   title: 'Hello, World!',
     *   tags: [ 'foo', 'bar', 'baz' ]
     * }
     */
    this.pipe(
      concat(function (body) {
        console.log(body.toString())
        //=> Lorem ipsum dolor sit amet consectetur adipisicing elit.
      })
    )
  })
)

callback is called with the frontmatter attributes, while the document body is simply passed through the stream. Also note that the this context of callback is the stream itself; this is useful if we want to change the flow of the stream depending on the parsed attributes.

API

const fastmatter = require('fastmatter')

fastmatter(string)

Parses the string and returns the parsed frontmatter attributes and document body.

fastmatter.stream([callback])

Calls callback with the parsed frontmatter attributes. The this context of callback is the stream itself. The document body is passed through the stream.

Installation

Install via yarn:

$ yarn add fastmatter

Or npm:

$ npm install --save fastmatter

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].