form

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package form interprets task lists in attached Markdown documents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyBulk added in v1.4.0

func ApplyBulk(items []Item, targets []int, answers map[string]Answer, answer Answer)

ApplyBulk selects every target, or deselects them when all are selected. Each answer copies the provenance in answer.

func CountSelected added in v1.4.0

func CountSelected(items []Item, targets []int, answers map[string]Answer) int

CountSelected reports how many of the target items are selected.

func Defaults

func Defaults(items []Item) map[string]Answer

func Fingerprint

func Fingerprint(items []Item, id string) (string, error)

Fingerprint excludes source positions but includes the complete ordered group.

func IsTextField added in v1.4.0

func IsTextField(item Item) bool

IsTextField distinguishes standalone string input from associated input.

func RankOrder added in v1.4.0

func RankOrder(items []Item, id string, answer Answer) (values []string, ranked bool)

RankOrder returns the values of a ranking in the answered order, or in source order with ranked false until a complete ranking is answered.

func Satisfied

func Satisfied(item Item, answer Answer) bool

func Selected

func Selected(item Item, answer Answer) bool

func Targets added in v1.4.0

func Targets(items []Item) (map[int][]int, error)

Targets maps the index of each select-all item to the indices of the answerable items it controls, following nested select-all items.

Types

type Answer

type Answer struct {
	Value    any    `json:"value"`
	Human    bool   `json:"human"`
	Author   string `json:"author,omitempty"`
	Revision string `json:"review_revision,omitempty"`
	Round    int    `json:"round,omitempty"`
	// Via names the select-all item whose human operation set this answer.
	Via string `json:"via,omitempty"`
	// Text holds the current associated input; unchecked checkbox input
	// remains a draft until that checkbox is selected again.
	Text string `json:"text,omitempty"`
	// Drafts holds per-choice input values while another option is selected.
	Drafts map[string]string `json:"drafts,omitempty"`
}

func SelectAnswer added in v1.4.0

func SelectAnswer(items []Item, item Item, previous Answer, selected bool, answer Answer) Answer

SelectAnswer preserves associated input when toggling a checkbox or switching choices. Each option keeps its own draft and initial suggestion.

type Heading added in v1.4.0

type Heading struct {
	Line int
	Text string
}

func Headings added in v1.4.0

func Headings(source string) ([]Heading, error)

Headings lists Markdown headings in source order so form items can be grouped by the section that asks them.

type InputType added in v1.4.0

type InputType string
const (
	InputFile      InputType = "file"
	InputDirectory InputType = "directory"
	InputPath      InputType = "path"
)

type Item

type Item struct {
	ID         string `json:"id"`
	Value      string `json:"value,omitempty"`
	Choice     bool   `json:"choice,omitempty"`
	Explicit   bool   `json:"explicit,omitempty"`
	Required   bool   `json:"required,omitempty"`
	Consent    bool   `json:"consent,omitempty"`
	Initial    bool   `json:"initial,omitempty"`
	Label      string `json:"label"`
	Definition string `json:"definition"`
	Line       int    `json:"line"`
	EndLine    int    `json:"end_line"`
	Offset     int    `json:"offset"`
	Metadata   []Span `json:"metadata,omitempty"`
	// Tags and SelectAll are sorted sets, so reordering keeps fingerprints.
	Tags      []string `json:"tags,omitempty"`
	SelectAll []string `json:"select_all,omitempty"`
	// Text adds string input to a control, or makes a standalone input field.
	Text bool `json:"text,omitempty"`
	// Type selects single-line path input; Text remains true for string fields.
	Type     InputType `json:"type,omitempty"`
	Default  string    `json:"default,omitempty"`
	Existing bool      `json:"existing,omitempty"`
	// Checkbox keeps a boolean control alongside an associated input.
	Checkbox bool `json:"checkbox,omitempty"`
	// Rank makes items sharing an ID one field ordered by the reviewer.
	Rank bool `json:"rank,omitempty"`
}

func Parse

func Parse(source string) ([]Item, error)

Parse uses the Markdown AST so examples, escaped lists, and quotations are inert.

type Span

type Span struct {
	Start int `json:"start"`
	End   int `json:"end"`
}

Jump to

Keyboard shortcuts

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