documentation
This commit is contained in:
parent
3badcb3af6
commit
2f56624c75
20
lib.go
20
lib.go
@ -1,3 +1,4 @@
|
|||||||
|
// Package textfmt can be used to format structured data into plain text for terminal, roff, markdown or HTML.
|
||||||
package textfmt
|
package textfmt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -106,6 +107,11 @@ func Cat(t ...Txt) Txt {
|
|||||||
return Txt{cat: t}
|
return Txt{cat: t}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 Title(level int, text string, manInfo ...TitleInfo) Entry {
|
func Title(level int, text string, manInfo ...TitleInfo) Entry {
|
||||||
if level != 0 {
|
if level != 0 {
|
||||||
return Entry{
|
return Entry{
|
||||||
@ -198,7 +204,6 @@ func Row(cells ...TableCell) TableRow {
|
|||||||
return TableRow{cells: cells}
|
return TableRow{cells: cells}
|
||||||
}
|
}
|
||||||
|
|
||||||
// when no header and markdown, header automatic
|
|
||||||
func Table(rows ...TableRow) Entry {
|
func Table(rows ...TableRow) Entry {
|
||||||
return Entry{typ: table, rows: rows}
|
return Entry{typ: table, rows: rows}
|
||||||
}
|
}
|
||||||
@ -241,7 +246,6 @@ func Sequence(items ...SyntaxItem) SyntaxItem {
|
|||||||
return SyntaxItem{sequence: items}
|
return SyntaxItem{sequence: items}
|
||||||
}
|
}
|
||||||
|
|
||||||
// top level on separate lines without delimiter
|
|
||||||
func Choice(items ...SyntaxItem) SyntaxItem {
|
func Choice(items ...SyntaxItem) SyntaxItem {
|
||||||
return SyntaxItem{choice: items}
|
return SyntaxItem{choice: items}
|
||||||
}
|
}
|
||||||
@ -259,7 +263,9 @@ func Wrap(e Entry, width int) Entry {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// indentFirst is relative to indent
|
// 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 indent parameter.
|
||||||
func Indent(e Entry, indent, indentFirst int) Entry {
|
func Indent(e Entry, indent, indentFirst int) Entry {
|
||||||
e.indent, e.indentFirst = indent, indentFirst
|
e.indent, e.indentFirst = indent, indentFirst
|
||||||
return e
|
return e
|
||||||
@ -282,17 +288,19 @@ func Runoff(out io.Writer, d Document) error {
|
|||||||
return renderRoff(out, d)
|
return renderRoff(out, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 Markdown(out io.Writer, d Document) error {
|
func Markdown(out io.Writer, d Document) error {
|
||||||
return renderMarkdown(out, d)
|
return renderMarkdown(out, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTMLFragment renders the input document as HTML fragments, without html and body tags.
|
||||||
func HTMLFragment(out io.Writer, doc Document) error {
|
func HTMLFragment(out io.Writer, doc Document) error {
|
||||||
// with the won HTML library
|
|
||||||
return renderHTMLFragment(out, doc)
|
return renderHTMLFragment(out, doc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if lang is empty, the lang attribute will be omitted
|
// HTMLFragment renders the input document as a HTML document. If the lang attribute is empty, it will be
|
||||||
|
// omitted from the html element.
|
||||||
func HTML(out io.Writer, doc Document, lang string) error {
|
func HTML(out io.Writer, doc Document, lang string) error {
|
||||||
// with the won HTML library
|
|
||||||
return renderHTML(out, doc, lang)
|
return renderHTML(out, doc, lang)
|
||||||
}
|
}
|
||||||
|
|||||||
9
license
Normal file
9
license
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2025 Arpad Ryszka
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
Loading…
Reference in New Issue
Block a user