yaml_front_matter v0.2.0 YamlFrontMatter

Parse a file or string containing front matter and a document body.

Front matter is a block of yaml wrapped between two lines containing ---. In this example, the front matter contains title: Hello, and the body is Hello, world:

---
title: Hello
---
Hello, world

After parsing the document, front matter is returned as a map, and the body as a string.

YamlFrontMatter.parse_file "hello_world.md"
{:ok, %{"title" => "Hello"}, "Hello, world"}    

Summary

Functions

Parse a string and return it’s front matter and body

Read a file, parse it’s contents, and return it’s front matter and body

Functions

parse(string)

Parse a string and return it’s front matter and body.

Returns {:ok, matter, body} on success (matter is a map), or {:error, error} on error.

iex> YamlFrontMatter.parse "---\ntitle: Hello\n---\nHello, world"
{:ok, %{"title" => "Hello"}, "Hello, world"}

iex> YamlFrontMatter.parse "---\ntitle: Hello\n--\nHello, world"
{:error, :invalid_front_matter}
parse_file(path)

Read a file, parse it’s contents, and return it’s front matter and body.

Returns {:ok, matter, body} on success (matter is a map), or {:error, error} on error.

iex> YamlFrontMatter.parse_file "test/fixtures/dummy.md"
{:ok, %{"title" => "Hello"}, "Hello, world\n"}

iex> YamlFrontMatter.parse_file "test/fixtures/idontexist.md"
{:error, :enoent}