frontmatter

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Validate

func Validate(doc *Document) error

Validate checks the document against strict YAML rules. Returns nil if valid, error describing the problem otherwise. Missing front matter is valid.

Types

type Document

type Document struct {
	// HasFrontMatter indicates whether front matter was found.
	HasFrontMatter bool
	// RawFrontMatter is the raw YAML text between the --- delimiters.
	RawFrontMatter string
	// Body is the Markdown content after the front matter.
	Body string
	// Node is the parsed yaml.Node tree (for minimal-change editing).
	Node *yaml.Node
	// OriginalContent is the original full file content.
	OriginalContent string
}

Document represents a parsed Markdown file with optional YAML front matter.

func Parse

func Parse(content string) (*Document, error)

Parse splits a Markdown document into front matter and body. If the file doesn't start with ---, HasFrontMatter is false and Body is the full content. If it starts with --- but YAML is invalid, returns an error.

func ParseAndValidate

func ParseAndValidate(content string) (*Document, error)

ParseAndValidate combines Parse and Validate.

func (*Document) Get

func (d *Document) Get(path pathsyntax.Path) *yaml.Node

Get retrieves the yaml.Node at the given path. Returns nil if not found or if there is no front matter.

func (*Document) GetValue

func (d *Document) GetValue(path pathsyntax.Path) interface{}

GetValue retrieves the Go value at the given path. Returns nil if path not found.

func (*Document) Render

func (d *Document) Render() string

Render produces the complete markdown content from the document.

func (*Document) Set

func (d *Document) Set(path pathsyntax.Path, yamlValue string, mode SetMode) error

Set sets a value at the given path in the document's front matter. If no front matter exists, it creates one. The yamlValue parameter is a YAML string that will be parsed.

func (*Document) Unset

func (d *Document) Unset(path pathsyntax.Path) bool

Unset removes a value at the given path. Returns true if something was removed, false if path not found.

type SetMode

type SetMode int

SetMode controls how values are merged.

const (
	// SetOverwrite replaces the value at the path entirely.
	SetOverwrite SetMode = iota
	// SetPatch merges maps recursively; arrays and scalars are replaced.
	SetPatch
)

Jump to

Keyboard shortcuts

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