Documentation
¶
Overview ¶
Package edit holds the note edits shared by the CLI, the MCP server, hooks and the app: building a new note, editing tags and properties in frontmatter, replacing or appending to the body. Every function works on the raw file bytes and changes only what it has to, so the rest of the file stays byte for byte (see package frontmatter).
Index ¶
- Constants
- Variables
- func AddTag(ts []string, t string) []string
- func Append(raw []byte, text string) []byte
- func Check(src []byte) error
- func New(text string, tags []string, props map[string]any, now time.Time) ([]byte, error)
- func Normalize(v any) any
- func Props(src []byte, set map[string]any, unset []string) ([]byte, error)
- func RemoveTag(ts []string, t string) []string
- func ReplaceBody(raw []byte, body string) []byte
- func TagList(v any) []string
- func Tags(src []byte, add, remove []string) ([]byte, []string, error)
Constants ¶
const CreatedKey = "created"
CreatedKey is the frontmatter key new notes are stamped with.
Variables ¶
var ErrInvalidTag = errors.New("invalid tag")
ErrInvalidTag is returned for tags that are empty after cleaning.
Functions ¶
func Append ¶
Append adds text at the end of the note on a line of its own and makes sure the file ends with a newline. Start text with an empty line for a new paragraph.
func Check ¶
Check refuses content whose frontmatter does not parse: a line-based edit could make it worse.
func New ¶
New builds the file of a new note: text, plus tags, props and a created timestamp in its frontmatter (merged into frontmatter text already has). Tags may be comma-separated lists. created is only added when text does not set it.
func Normalize ¶
Normalize turns JSON-decoded values into what YAML should show: whole numbers as integers, recursively through lists and maps.
func Props ¶
Props sets and removes frontmatter keys. Values are normalized from JSON first: whole float64 numbers become integers, so 2 stays "2".
func ReplaceBody ¶
ReplaceBody returns raw with everything after the frontmatter replaced by body. The frontmatter block stays byte for byte.
Types ¶
This section is empty.