okf

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package okf is the Open Knowledge Format, publishable without the rest of keepsake.

Index

Constants

View Source
const (
	MaxPath  = 1024
	MaxBody  = 256 * 1024
	MaxTitle = 4096
)

Postgres limits in bytes, refused in advance so the agent gets a sentence instead of a driver error.

Variables

View Source
var ReservedPaths = map[string]bool{"index": true, "log": true}

ReservedPaths are the files a bundle export writes at its root, so no concept may hold one.

Functions

func ExtractLinks(body, p string) []string

ExtractLinks returns the concept paths body links to, deduplicated in first-seen order. It matches Python's (?<!!)\[[^\]]*\]\(\s*([^)\s]*)(?:\s+[^)]*)?\s*\) in linear time.

func IsDecimal

func IsDecimal(s string) bool

IsDecimal is Python's str.isdecimal() over ASCII: non-empty and every byte a digit.

func PyReprString

func PyReprString(s string) string

PyReprString is Python's repr(str): single quotes unless only double quotes avoid escaping.

func Resolve

func Resolve(target, directory string) (string, bool)

Resolve returns the concept path a link target names, relative to directory.

func Serialize

func Serialize(c Concept) (string, error)

Serialize renders a concept as an OKF document, failing only on a non-finite float.

func Validate

func Validate(c Concept) []string

Validate returns every rule c breaks. An empty result means valid.

Types

type Concept

type Concept struct {
	Path        string
	Type        string
	Title       string
	Description string
	Body        string
	Frontmatter *Map
	Links       []string
	Version     int
}

Concept is a single knowledge unit: a path, its frontmatter and its markdown body.

func Parse

func Parse(text, path string) (Concept, error)

Parse reads an OKF document. Frontmatter keeps only the fields Concept does not promote.

type Map

type Map struct {
	// contains filtered or unexported fields
}

Map is an insertion-ordered JSON object of string, bool, nil, json.Number, int, NonFinite, []any or *Map.

func NewMap

func NewMap() *Map

func (*Map) Delete

func (m *Map) Delete(k string)

func (*Map) Get

func (m *Map) Get(k string) (any, bool)

func (*Map) Keys

func (m *Map) Keys() []string

func (*Map) Len

func (m *Map) Len() int

func (*Map) MarshalJSON

func (m *Map) MarshalJSON() ([]byte, error)

func (*Map) Set

func (m *Map) Set(k string, v any)

Set adds or replaces a value. An existing key keeps its position.

func (*Map) UnmarshalJSON

func (m *Map) UnmarshalJSON(data []byte) error

UnmarshalJSON walks tokens so that key order survives; a map[string]any would lose it.

type NonFinite

type NonFinite string

NonFinite is a YAML .inf, -.inf or .nan. JSON cannot hold it, so it refuses to marshal.

const (
	PyInf    NonFinite = "inf"
	PyNegInf NonFinite = "-inf"
	PyNaN    NonFinite = "nan"
)

func (NonFinite) MarshalJSON

func (n NonFinite) MarshalJSON() ([]byte, error)

type YAMLError

type YAMLError struct{ Msg string }

YAMLError is frontmatter that cannot be read. Callers prefix it with the file name.

func (YAMLError) Error

func (e YAMLError) Error() string

Directories

Path Synopsis
internal
yaml
Package yaml implements YAML support for the Go language.
Package yaml implements YAML support for the Go language.

Jump to

Keyboard shortcuts

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