frontmatter

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package frontmatter splits a leading TOML block off a Markdown file and decodes it strictly, with positions in the file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(file string, src []byte, firstLine int, v any) error

Decode decodes TOML into v with unknown keys rejected; positions are offset by firstLine-1.

func Key added in v0.3.0

func Key(k string) string

Key is k written as a TOML key, quoted only where it needs it.

func Positions

func Positions(src []byte, firstLine int) map[string]Position

Positions maps each key path of a TOML document to where its value starts, with lines offset by firstLine-1. Paths are dotted keys; array elements and array-table entries carry their index ("paths[1]", "headline.new[0].when"). A table or an array maps to its key. It returns what it read before a syntax error.

func Split

func Split(file, raw string) (head string, body string, bodyLine int, err error)

Split separates a leading "+++" TOML block; bodyLine is the 1-based line where the body starts.

func Value added in v0.3.0

func Value(v any) (string, error)

Value is v written as one TOML value, as go-toml encodes it; a table is an error.

Types

type Error

type Error struct {
	File      string
	Line, Col int
	Key, Msg  string
}

func (*Error) Error

func (e *Error) Error() string

Error is "file:line:col: key: msg"; the key is left out when empty.

type Position

type Position struct{ Line, Col int }

Position is a 1-based line and column in a file.

Jump to

Keyboard shortcuts

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