Documentation ¶
Overview ¶
Package ansihtml parses text formatted with ANSI escape sequences and outputs text suitable for display in a HTML <pre> tag.
Text effects are encoded as <span> tags with style attributes or various classes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertToHTML ¶
ConvertToHTML converts ansiBytes to HTML where ANSI escape sequences have been translated to <span> tags with appropriate style attributes.
func ConvertToHTMLWithClasses ¶
ConvertToHTMLWithClasses converts ansiBytes to HTML where ANSI escape sequences have been translated to <span> tags with appropriate classes set.
classPrefix will be prefixed to the standard class names in the output.
If noStyles is true, no style tags will be emitted for 256-color and 24-bit color text; instead, these color sequences will have no effect.
A span in the output may have any combination of these classes:
- 'bold' or 'faint'
- 'italic' or 'fraktur'
- 'double-underline' or 'underline'
- 'strikethrough'
- 'overline'
- 'slow-blink' or 'fast-blink'
- 'invert'
- 'hide'
- one of 'font-{n}' where n is between 1 and 9
- 'proportional'
- 'superscript' or 'subscript'
- 'fg-{color}', 'bg-{color}', and 'underline-{color}' where color is one of
- black
- red
- green
- yellow
- blue
- magenta
- cyan
- white
- bright-black
- bright-red
- bright-green
- bright-yellow
- bright-blue
- bright-magenta
- bright-cyan
- bright-white
Types ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses ANSI-encoded console output from an io.Reader.
func NewParser ¶
NewParser creates a Parser which reads from rd and writes output with escape sequences removed to w.
func (*Parser) Parse ¶
func (p *Parser) Parse(escapeHandler func(finalByte byte, intermediateBytes, parameterBytes []byte) error) error
Parse reads from the io.Reader, calling escapeHandler with any parsed ANSI escape sequences and writing normal output to the io.Writer, until either EOF is reached or an error occurs.
Writes to w and calls to escapeHandler are done in the same order as data is read from the io.Reader, meaning escapeHandler can write to the io.Writer to insert text formatting data as necessary.
escapeHandler takes the finalByte and intermediateBytes from the escape sequence and any parameterBytes from after the escape sequence as parameters. For example, the escape sequence '\x1b[0;33m' will result in escapeHandler being called with finalByte '[', intermediateBytes ”, and parameterBytes '0;33m'.
intermediateBytes is rarely present in ANSI escape sequences, with one example being the switching between JIS encodings done by ISO-2022-JP.