edit

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const CreatedKey = "created"

CreatedKey is the frontmatter key new notes are stamped with.

Variables

View Source
var ErrInvalidTag = errors.New("invalid tag")

ErrInvalidTag is returned for tags that are empty after cleaning.

Functions

func AddTag

func AddTag(ts []string, t string) []string

AddTag appends t unless ts has it already, ignoring case.

func Append

func Append(raw []byte, text string) []byte

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

func Check(src []byte) error

Check refuses content whose frontmatter does not parse: a line-based edit could make it worse.

func New

func New(text string, tags []string, props map[string]any, now time.Time) ([]byte, error)

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

func Normalize(v any) any

Normalize turns JSON-decoded values into what YAML should show: whole numbers as integers, recursively through lists and maps.

func Props

func Props(src []byte, set map[string]any, unset []string) ([]byte, error)

Props sets and removes frontmatter keys. Values are normalized from JSON first: whole float64 numbers become integers, so 2 stays "2".

func RemoveTag

func RemoveTag(ts []string, t string) []string

RemoveTag returns ts without t, ignoring case.

func ReplaceBody

func ReplaceBody(raw []byte, body string) []byte

ReplaceBody returns raw with everything after the frontmatter replaced by body. The frontmatter block stays byte for byte.

func TagList

func TagList(v any) []string

TagList reads the tags property as Obsidian does: a list, or a string of comma or space separated tags. Tags are cleaned and deduplicated ignoring case.

func Tags

func Tags(src []byte, add, remove []string) ([]byte, []string, error)

Tags adds and removes tags in the frontmatter "tags" list and returns the new content and tag list. Removing the last tag removes the key; inline #tags in the body are not touched. Unchanged tags return src as is.

Types

This section is empty.

Jump to

Keyboard shortcuts

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