document

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package document turns a file's bytes into a Document: raw content, fence-aware source lines, and a parsed frontmatter/data map. It is the format-agnostic substrate every rule reads from.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	Path        string
	Format      Format
	Raw         []byte
	Lines       []Line
	Frontmatter map[string]any // markdown: parsed frontmatter; data: whole file
	Body        []byte         // markdown content after frontmatter (nil for data)
	BodyOffset  int            // byte offset in Raw where Body begins (0 for data)
}

Document is the parsed view of a single file.

func Parse

func Parse(format Format, path string, raw []byte) (*Document, error)

Parse dispatches to the parser registered for format.

func ParseData

func ParseData(path string, raw []byte) (*Document, error)

ParseData loads a YAML/TOML/JSON data file into Document.Frontmatter (the whole file becomes the parsed map). Data files have no body or AST.

func ParseMarkdown

func ParseMarkdown(path string, raw []byte) (*Document, error)

ParseMarkdown builds a markdown Document: it extracts YAML/TOML/JSON frontmatter into a map and records where the body begins.

type Format

type Format string

Format identifies how a file is parsed and which rules apply to it.

const (
	Markdown Format = "markdown"
	Data     Format = "data"
)

type Line

type Line struct {
	Num     int    // 1-based line number
	Text    string // line content without the trailing newline
	Start   int    // byte offset of the line start in Document.Raw
	End     int    // byte offset just past Text (before the newline)
	InFence bool   // true when the line is INSIDE a fenced code block
}

Line is one source line with byte offsets and fenced-code-block state.

func SplitLines

func SplitLines(raw []byte) []Line

SplitLines splits raw into fence-aware Lines. A fence delimiter line toggles the in-fence state but is itself reported with InFence=false; only the lines strictly between an opening and closing delimiter are InFence=true.

type ParseFunc

type ParseFunc func(path string, raw []byte) (*Document, error)

ParseFunc builds a Document from a file's bytes.

Jump to

Keyboard shortcuts

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