format

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: MIT Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Escape

func Escape(s string) string

Escape escapes special Markdown characters.

func FromJSON

func FromJSON(data []byte, v any) error

FromJSON unmarshals JSON data.

func ToJSON

func ToJSON(v any) ([]byte, error)

ToJSON marshals data to JSON with indentation.

func ToJSONCompact

func ToJSONCompact(v any) ([]byte, error)

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

func ParseFormat(s string) Format

ParseFormat parses a format string into a Format type. Returns FormatText for unrecognized formats.

func (Format) FileExtension

func (f Format) FileExtension() string

FileExtension returns the typical file extension for this format.

func (Format) String

func (f Format) String() string

String returns the format as a string.

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) Bold

func (b *MarkdownBuilder) Bold(text string)

Bold writes bold text.

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) Code

func (b *MarkdownBuilder) Code(text string)

Code writes inline code.

func (*MarkdownBuilder) CodeBlock

func (b *MarkdownBuilder) CodeBlock(language, code string)

CodeBlock writes a fenced code block.

func (*MarkdownBuilder) H1

func (b *MarkdownBuilder) H1(text string)

H1 writes a level 1 heading.

func (*MarkdownBuilder) H2

func (b *MarkdownBuilder) H2(text string)

H2 writes a level 2 heading.

func (*MarkdownBuilder) H3

func (b *MarkdownBuilder) H3(text string)

H3 writes a level 3 heading.

func (*MarkdownBuilder) H4

func (b *MarkdownBuilder) H4(text string)

H4 writes a level 4 heading.

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 (b *MarkdownBuilder) Link(text, url string)

Link writes a Markdown link.

func (*MarkdownBuilder) Newline

func (b *MarkdownBuilder) Newline()

Newline writes a newline.

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) Reset

func (b *MarkdownBuilder) Reset()

Reset clears the builder.

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 NewTOONBuilder

func NewTOONBuilder() *TOONBuilder

NewTOONBuilder creates a new TOON builder.

func (*TOONBuilder) Bytes

func (b *TOONBuilder) Bytes() []byte

Bytes returns the built TOON as bytes.

func (*TOONBuilder) Dedent

func (b *TOONBuilder) Dedent()

Dedent decreases the indentation level.

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) Indent

func (b *TOONBuilder) Indent()

Indent increases the indentation level.

func (*TOONBuilder) List

func (b *TOONBuilder) List(items []string)

List writes a list of values.

func (*TOONBuilder) ListItem

func (b *TOONBuilder) ListItem(item string)

ListItem writes a single list item.

func (*TOONBuilder) Newline

func (b *TOONBuilder) Newline()

Newline writes a blank line.

func (*TOONBuilder) String

func (b *TOONBuilder) String() string

String returns the built TOON string.

Jump to

Keyboard shortcuts

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