markdown

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package markdown provides utilities for parsing and creating Markdown files with optional frontmatter.

Index

Constants

View Source
const DefaultDelimiter = "---"

The DefaultDelimiter is used to determine the bounds of frontmatter if no other delimiter is set.

Variables

This section is empty.

Functions

func Decode

func Decode(r io.Reader, fm any, body io.Writer) error

Decode uses the default Decoder to parse the contents of r into its respective frontmatter (if any) and body content.

func Encode

func Encode(w io.Writer, fm any, body io.Reader) error

Encode uses the default Encoder to write the provided frontmatter (in YAML) and body contents to w.

Types

type Decoder

type Decoder struct {
	// The delimiter used to determine the bounds of frontmatter.
	Delimiter []byte
}

Decoder parses markdown content into frontmatter and body components.

func NewDecoder

func NewDecoder() *Decoder

NewDecoder returns a Decoder configured with the default options.

func (*Decoder) Decode

func (dec *Decoder) Decode(r io.Reader, fm any, body io.Writer) error

Decode reads the contents of r and extracts them into their respective frontmatter (if any) and body contents. If the delimiter is found at the start of the contents of r, it is assumed that the file contains YAML frontmatter and it MUST have a corresponding closing delimiter or the method will return an error.

If fm is provided but no frontmatter is present in r, nothing will be written to fm. Likewise, if fm is not provided but frontmatter exists, the frontmatter will be ignored.

Similarly, if body is not provided, it will be skipped.

type Encoder

type Encoder struct {
	// The delimiter used to determine the bounds of frontmatter.
	Delimiter []byte
}

Encoder writes markdown files with optional YAML frontmatter.

func NewEncoder

func NewEncoder() *Encoder

NewEncoder returns a Encoder configured with the default options.

func (*Encoder) Encode

func (enc *Encoder) Encode(w io.Writer, fm any, body io.Reader) error

Encode writes the provided frontmatter (in YAML) and body contents to w. If no frontmatter is provided, an empy frontmatter block will be added to the beginning of the output.

Jump to

Keyboard shortcuts

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