textfmt

package module
v0.0.0-...-fed32c8 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: MIT Imports: 9 Imported by: 0

README

textfmt

Library for formatting structured data in plain text for terminal, roff, markup or HTML.

Documentation:

Made in Berlin, DE

Documentation

Overview

Package textfmt can be used to format structured data into plain text for terminal, roff, markdown or HTML.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTML

func HTML(out io.Writer, doc Document, lang string) error

HTML renders the input document as an HTML document. If the lang attribute is empty, it will be omitted from the html element.

func HTMLFragment

func HTMLFragment(out io.Writer, doc Document) error

HTMLFragment renders the input document as HTML fragments, without html and body tags.

func Markdown

func Markdown(out io.Writer, d Document) error

Markdown can be used to render the input document in basic markdown format. The only not entirely standard output feature is the support for tables.

func Runoff

func Runoff(out io.Writer, d Document) error

Runoff is an attempt to render roff format. It is primarily targeting man pages. While it may be possible to use for other purposes, the man macro will likely be required to render the output.

Text is always wrapped, or as controlled by the roff processor, except for tables. The Wrap instrunction has no effect, except for tables.

func Teletype

func Teletype(out io.Writer, d Document) error

Teletype can be used to render the input document in plain text usable to print in TTY terminals, typically directly to the standard output.

Types

type DefinitionItem

type DefinitionItem struct {
	// contains filtered or unexported fields
}

func Definition

func Definition(name, value Txt, style ...ItemStyle) DefinitionItem

Definition creates a definition list item for bulleted or numbered definition lists. Item style may behave different depending ont the output format.

type Document

type Document struct {
	// contains filtered or unexported fields
}

func Doc

func Doc(e ...Entry) Document

type Entry

type Entry struct {
	// contains filtered or unexported fields
}

func CodeBlock

func CodeBlock(codeBlock string) Entry

func DefinitionList

func DefinitionList(items ...DefinitionItem) Entry

func Indent

func Indent(e Entry, indent, indentFirst int) Entry

Indent can be used to control indentation. Indentation may behave different depending on the output format. The indent parameter sets the indentation in spaces for a section. The indentFirst parameter sets the indentation for the first line in the section and it is relative to the indent parameter.

func List

func List(items ...ListItem) Entry

func NumberedDefinitionList

func NumberedDefinitionList(items ...DefinitionItem) Entry

func NumberedList

func NumberedList(items ...ListItem) Entry

func Paragraph

func Paragraph(t Txt) Entry

func Syntax

func Syntax(items ...SyntaxItem) Entry

func Table

func Table(rows ...TableRow) Entry

func Title

func Title(level int, text string, manInfo ...TitleInfo) Entry

Title can be used for document titles or subtitles. Titles with different levels behave differently with the different output formats. TTY output does prints every level the same way. HTML and markdown titles utilize the level info from 0 to 5, where 0 will mean H1. In case of Roff, if the level is 0 and the ManSection is set, the output will be in manpage title format, expecting the man macro to be used when processing the roff output.

func Wrap

func Wrap(e Entry, width int) Entry

Wrap can be used to wrap text into multiple similar length lines of maximum width. It may behave different for different entries and different output types.

type ItemStyle

type ItemStyle struct {
	// contains filtered or unexported fields
}

func Bullet

func Bullet(b string) ItemStyle

func NoBullet

func NoBullet() ItemStyle

type ListItem

type ListItem struct {
	// contains filtered or unexported fields
}

func Item

func Item(text Txt, style ...ItemStyle) ListItem

Item creates a list item for bulleted or numbered lists. Item style may behave different depending ont the output format.

type SyntaxItem

type SyntaxItem struct {
	// contains filtered or unexported fields
}

func Choice

func Choice(items ...SyntaxItem) SyntaxItem

func OneOrMore

func OneOrMore(item SyntaxItem) SyntaxItem

func Optional

func Optional(item SyntaxItem) SyntaxItem

func Required

func Required(item SyntaxItem) SyntaxItem

func Sequence

func Sequence(items ...SyntaxItem) SyntaxItem

func Symbol

func Symbol(text string) SyntaxItem

func ZeroOrMore

func ZeroOrMore(item SyntaxItem) SyntaxItem

type TableCell

type TableCell struct {
	// contains filtered or unexported fields
}

func Cell

func Cell(text Txt) TableCell

type TableRow

type TableRow struct {
	// contains filtered or unexported fields
}
func Header(cells ...TableCell) TableRow

func Row

func Row(cells ...TableCell) TableRow

type TitleInfo

type TitleInfo struct {
	// contains filtered or unexported fields
}

func ManCategory

func ManCategory(c string) TitleInfo

func ManSection

func ManSection(s int) TitleInfo

func ReleaseDate

func ReleaseDate(d time.Time) TitleInfo

func ReleaseVersion

func ReleaseVersion(v string) TitleInfo

type Txt

type Txt struct {
	// contains filtered or unexported fields
}

func Bold

func Bold(t Txt) Txt

func Cat

func Cat(t ...Txt) Txt

func Italic

func Italic(t Txt) Txt
func Link(label, uri string) Txt

func Text

func Text(text string) Txt

Jump to

Keyboard shortcuts

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