Documentation
¶
Overview ¶
Package format provides output format utilities for structured documents. It includes support for TOON (Token-Oriented Object Notation), JSON, and Markdown output formats.
Index ¶
- func Escape(s string) string
- func FromJSON(data []byte, v any) error
- func ToJSON(v any) ([]byte, error)
- func ToJSONCompact(v any) ([]byte, error)
- type Format
- type MarkdownBuilder
- func (b *MarkdownBuilder) Blockquote(text string)
- func (b *MarkdownBuilder) Bold(text string)
- func (b *MarkdownBuilder) BulletList(items []string)
- func (b *MarkdownBuilder) Bytes() []byte
- func (b *MarkdownBuilder) Checkbox(checked bool, text string)
- func (b *MarkdownBuilder) Code(text string)
- func (b *MarkdownBuilder) CodeBlock(language, code string)
- func (b *MarkdownBuilder) H1(text string)
- func (b *MarkdownBuilder) H2(text string)
- func (b *MarkdownBuilder) H3(text string)
- func (b *MarkdownBuilder) H4(text string)
- func (b *MarkdownBuilder) HorizontalRule()
- func (b *MarkdownBuilder) Image(alt, url string)
- func (b *MarkdownBuilder) Italic(text string)
- func (b *MarkdownBuilder) Link(text, url string)
- func (b *MarkdownBuilder) Newline()
- func (b *MarkdownBuilder) NumberedList(items []string)
- func (b *MarkdownBuilder) Paragraph(text string)
- func (b *MarkdownBuilder) Reset()
- func (b *MarkdownBuilder) String() string
- func (b *MarkdownBuilder) Table(headers []string, rows [][]string)
- func (b *MarkdownBuilder) Text(text string)
- type TOONBuilder
- func (b *TOONBuilder) Bytes() []byte
- func (b *TOONBuilder) Dedent()
- func (b *TOONBuilder) Field(key string, value any)
- func (b *TOONBuilder) FieldIf(key string, value string)
- func (b *TOONBuilder) Header(name string)
- func (b *TOONBuilder) Indent()
- func (b *TOONBuilder) List(items []string)
- func (b *TOONBuilder) ListItem(item string)
- func (b *TOONBuilder) Newline()
- func (b *TOONBuilder) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToJSONCompact ¶
ToJSONCompact marshals data to JSON without indentation.
Types ¶
type Format ¶
type Format string
Format represents an output format type.
const ( FormatTOON Format = "toon" FormatJSON Format = "json" FormatJSONCompact Format = "json-compact" FormatMarkdown Format = "markdown" FormatText Format = "text" )
Supported output formats.
func ParseFormat ¶
ParseFormat parses a format string into a Format type. Returns FormatText for unrecognized formats.
func (Format) FileExtension ¶
FileExtension returns the typical file extension for this format.
type MarkdownBuilder ¶
type MarkdownBuilder struct {
// contains filtered or unexported fields
}
MarkdownBuilder helps construct Markdown-formatted output.
func NewMarkdownBuilder ¶
func NewMarkdownBuilder() *MarkdownBuilder
NewMarkdownBuilder creates a new Markdown builder.
func (*MarkdownBuilder) Blockquote ¶
func (b *MarkdownBuilder) Blockquote(text string)
Blockquote writes a blockquote.
func (*MarkdownBuilder) BulletList ¶
func (b *MarkdownBuilder) BulletList(items []string)
BulletList writes an unordered list.
func (*MarkdownBuilder) Bytes ¶
func (b *MarkdownBuilder) Bytes() []byte
Bytes returns the built Markdown as bytes.
func (*MarkdownBuilder) Checkbox ¶
func (b *MarkdownBuilder) Checkbox(checked bool, text string)
Checkbox writes a task list item.
func (*MarkdownBuilder) CodeBlock ¶
func (b *MarkdownBuilder) CodeBlock(language, code string)
CodeBlock writes a fenced code block.
func (*MarkdownBuilder) HorizontalRule ¶
func (b *MarkdownBuilder) HorizontalRule()
HorizontalRule writes a horizontal rule.
func (*MarkdownBuilder) Image ¶
func (b *MarkdownBuilder) Image(alt, url string)
Image writes a Markdown image.
func (*MarkdownBuilder) Italic ¶
func (b *MarkdownBuilder) Italic(text string)
Italic writes italic text.
func (*MarkdownBuilder) Link ¶
func (b *MarkdownBuilder) Link(text, url string)
Link writes a Markdown link.
func (*MarkdownBuilder) NumberedList ¶
func (b *MarkdownBuilder) NumberedList(items []string)
NumberedList writes an ordered list.
func (*MarkdownBuilder) Paragraph ¶
func (b *MarkdownBuilder) Paragraph(text string)
Paragraph writes a paragraph.
func (*MarkdownBuilder) String ¶
func (b *MarkdownBuilder) String() string
String returns the built Markdown string.
func (*MarkdownBuilder) Table ¶
func (b *MarkdownBuilder) Table(headers []string, rows [][]string)
Table writes a Markdown table.
func (*MarkdownBuilder) Text ¶
func (b *MarkdownBuilder) Text(text string)
Text writes text without trailing newlines.
type TOONBuilder ¶
type TOONBuilder struct {
// contains filtered or unexported fields
}
TOONBuilder helps construct TOON-formatted output.
func (*TOONBuilder) Bytes ¶
func (b *TOONBuilder) Bytes() []byte
Bytes returns the built TOON as bytes.
func (*TOONBuilder) Field ¶
func (b *TOONBuilder) Field(key string, value any)
Field writes a key-value field.
func (*TOONBuilder) FieldIf ¶
func (b *TOONBuilder) FieldIf(key string, value string)
FieldIf writes a key-value field only if the value is non-empty.
func (*TOONBuilder) Header ¶
func (b *TOONBuilder) Header(name string)
Header writes a section header.
func (*TOONBuilder) ListItem ¶
func (b *TOONBuilder) ListItem(item string)
ListItem writes a single list item.
func (*TOONBuilder) String ¶
func (b *TOONBuilder) String() string
String returns the built TOON string.