package module
v0.0.0-...-8a0b0a7 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2021 License: MIT Imports: 7 Imported by: 34


front Build Status GoDocCoverage Status

extracts frontmatter from text files with ease.


  • Custom delimiters. You are free to register any delimiter of your choice. Provided its a three character string. e.g +++, $$$, ---, %%%
  • Custom Handlers. Anything that implements HandlerFunc can be used to decode the values from the frontmatter text, you can see the JSONHandler for how to implement one.
  • Support YAML frontmatter
  • Support JSON frontmatter.


go get

How to use

package main

import (


var txt = `+++

# Body
Over my dead body

func main() {
	m := front.NewMatter()
	m.Handle("+++", front.JSONHandler)
	f, body, err := m.Parse(strings.NewReader(txt))
	if err != nil {

	fmt.Printf("The front matter is:\n%#v\n", f)
	fmt.Printf("The body is:\n%q\n", body)

Please see the tests formore details


This project is under the MIT Licence. See the LICENCE file for the full license text.



Package front is a frontmatter extraction library.



This section is empty.


View Source
var (
	//ErrIsEmpty is an error indicating no front matter was found
	ErrIsEmpty = errors.New("front: an empty file")

	//ErrUnknownDelim is returned when the delimiters are not known by the
	//FrontMatter implementation.
	ErrUnknownDelim = errors.New("front: unknown delim")


func JSONHandler

func JSONHandler(front string) (map[string]interface{}, error)

JSONHandler implements HandlerFunc interface. It extracts front matter data from the given string argument by interpreting it as a json string.

func YAMLHandler

func YAMLHandler(front string) (map[string]interface{}, error)

YAMLHandler decodes ymal string into a go map[string]interface{}


type HandlerFunc

type HandlerFunc func(string) (map[string]interface{}, error)

HandlerFunc is an interface for a function that process front matter text.

type Matter

type Matter struct {
	// contains filtered or unexported fields

Matter is all what matters here.

func NewMatter

func NewMatter() *Matter

NewMatter creates a new Matter instance

func (*Matter) Handle

func (m *Matter) Handle(delim string, fn HandlerFunc)

Handle registers a handler for the given frontmatter delimiter

func (*Matter) Parse

func (m *Matter) Parse(input io.Reader) (front map[string]interface{}, body string, err error)

Parse parses the input and extract the frontmatter

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL