Skip to content
This repository has been archived by the owner on Aug 30, 2020. It is now read-only.
/ front-matter.dart Public archive
forked from izolate/front-matter

Extracts YAML front matter from a file or string

License

Notifications You must be signed in to change notification settings

mpfaff/front-matter.dart

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Front Matter

A front matter parser that extracts YAML metadata from the start of a file or string.

Build Status

Front matter is a concept heavily borrowed from Jekyll, and other static site generators, referring to a block of YAML in the header of a file representing the file's metadata.

Usage

Suppose you have the following Markdown file:

---
title: "Hello, world!"
author: "izolate"
---

This is an example.

Use parse to parse a string, or parseFile to read a file and parse its contents.

import 'dart:io';
import 'package:front_matter/front_matter.dart' as front_matter;

// Example 1 - parse file contents.
void example1() async {
  var file = new File('/path/to/file.md');
  var fileContents = await file.readAsString();
  var doc = front_matter.parse(fileContents);
  
  print(doc.data['title']); // "Hello, world!"
  print(doc.content);       // "This is an example."
}

// Example 2 - read file and parse contents.
void example2() async {
  var doc = await front_matter.parseFile('path/to/file.md');

  print(doc.data['title']); // "Hello, world!"
  print(doc.content);       // "This is an example."
}

I recommend using the import prefix front_matter due to the ambiguity of the method names.

API

FrontMatterDocument parse(String text, {String delimiter = "---"})

Parse a string, return a FrontMatterDocument with results.

Future<FrontMatterDocument> parseFile(String path, {String delimiter = "---"})

Read a file and parse its contents, return a Future<FrontMatterDocument> with results.

About

Extracts YAML front matter from a file or string

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 100.0%