Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HtmlToPlain ¶
HtmlToPlain converts an HTML code to machine-readable plain text content
Primary goals are plain text preview, search indexing, etc.
plain, err := HtmlToPlain("<h1>Heading</h1>\n<p>Lorem ipsum "dolor".</p>") if err != nil { return err } println(plain)
prints:
Heading Lorem ipsum "dolor".
Types ¶
type Table ¶ added in v0.2.0
type Table interface { // AddCol adds new column to the end // // All existing rows will be kept unchanged, and so the new column will be // empty. // // A `spec` is a column display name optionally prefixed with // special any of the following control characters: // // - `<` align left // - `>` align right // - `|` align center // - `.` hidden by default AddCol(spec string) // AddRow adds data for further output // // All the rows added are stored in memory as already formatted output. // Data already added one cannot be changed later. AddRow(values ...any) // FormatCol sets format by fmt.Printf() to display the given column data // // Will have effect only for further calls to AddRow(). // // Set empty string to remove format. By default, format is not defined, and // values will be printed with fmt.Sprint(). // // tbl := NewTable("Foo", "|Bar", ">Lorem ipsum") // tbl.FormatCol(2, "%0.2f") FormatCol(i int, format string) // HideCol hides the given column from output HideCol(i int) // UnhideCol reverts hidden flag the given column UnhideCol(i int) // ColsCount returns count of defined columns ColsCount() int // ColsCountVisible returns count of visible columns ColsCountVisible() int // RowsCount gets number of all rows with headers // // It's about logical rows count rather than number of text lines with all // delimiters. RowsCount() int // RowsCountData gets number of data rows without header row. // // It's about logical rows count rather than number of text lines with all // delimiters. RowsCountData() int // StringFull returns text table output with single-line delimiters between // all data rows and double-line delimiter for header rows StringFull() string // StringCompact returns text table output with row delimiter only for // header row StringCompact() string }
func NewTable ¶ added in v0.2.0
NewTable creates Table interface to form text table output
The `columns` are shortcut for Table.AddCol().
tbl := NewTable("Foo", "|Bar", ">Lorem ipsum") tbl.FormatCol(2, "%0.2f") tbl.AddRow("lol", true, 42.0) tbl.AddRow("q", false, 234.0) tbl.AddRow("xy", "-", 1234.56) print(tbl.StringFull()) print(tbl.StringCompact())
outputs
┌─────┬───────┬─────────────┐ │ Foo │ Bar │ Lorem ipsum │ ╞═════╪═══════╪═════════════╡ │ lol │ true │ 42.00 │ ├─────┼───────┼─────────────┤ │ q │ false │ 234.00 │ ├─────┼───────┼─────────────┤ │ xy │ - │ 1234.56 │ └─────┴───────┴─────────────┘ ┌─────┬───────┬─────────────┐ │ Foo │ Bar │ Lorem ipsum │ ╞═════╪═══════╪═════════════╡ │ lol │ true │ 42.00 │ │ q │ false │ 234.00 │ │ xy │ - │ 1234.56 │ └─────┴───────┴─────────────┘
Click to show internal directories.
Click to hide internal directories.