front_matter 1.0.1 copy "front_matter: ^1.0.1" to clipboard
front_matter: ^1.0.1 copied to clipboard

outdated

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

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.

3
likes
0
pub points
20%
popularity

Publisher

unverified uploader

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

Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (LICENSE)

Dependencies

yaml

More

Packages that depend on front_matter