package formatters
import "github.com/alecthomas/chroma/v2/formatters"
Index ¶
- Variables
- func Get(name string) chroma.Formatter
- func Names() []string
- func Register(name string, formatter chroma.Formatter) chroma.Formatter
Variables ¶
var ( // NoOp formatter. NoOp = Register("noop", chroma.FormatterFunc(func(w io.Writer, s *chroma.Style, iterator chroma.Iterator) error { for t := iterator(); t != chroma.EOF; t = iterator() { if _, err := io.WriteString(w, t.Value); err != nil { return err } } return nil })) SVG = Register("svg", svg.New(svg.EmbedFont("Liberation Mono", svg.FontLiberationMono, svg.WOFF))) )
var Fallback = NoOp
Fallback formatter.
var JSON = Register("json", chroma.FormatterFunc(func(w io.Writer, s *chroma.Style, it chroma.Iterator) error { if _, err := fmt.Fprintln(w, "["); err != nil { return err } i := 0 for t := it(); t != chroma.EOF; t = it() { if i > 0 { if _, err := fmt.Fprintln(w, ","); err != nil { return err } } i++ bytes, err := json.Marshal(t) if err != nil { return err } if _, err := fmt.Fprint(w, " "+string(bytes)); err != nil { return err } } if _, err := fmt.Fprintln(w); err != nil { return err } if _, err := fmt.Fprintln(w, "]"); err != nil { return err } return nil }))
JSON formatter outputs the raw token structures as JSON.
var Registry = map[string]chroma.Formatter{}
Registry of Formatters.
var TTY = Register("terminal", &indexedTTYFormatter{ttyTables[8]})
TTY is an 8-colour terminal formatter.
The Lab colour space is used to map RGB values to the most appropriate index colour.
var TTY16 = Register("terminal16", &indexedTTYFormatter{ttyTables[16]})
TTY16 is a 16-colour terminal formatter.
It uses \033[3xm for normal colours and \033[90Xm for bright colours.
The Lab colour space is used to map RGB values to the most appropriate index colour.
var TTY16m = Register("terminal16m", chroma.FormatterFunc(trueColourFormatter))
TTY16m is a true-colour terminal formatter.
var TTY256 = Register("terminal256", &indexedTTYFormatter{ttyTables[256]})
TTY256 is a 256-colour terminal formatter.
The Lab colour space is used to map RGB values to the most appropriate index colour.
var TTY8 = Register("terminal8", &indexedTTYFormatter{ttyTables[8]})
TTY8 is an 8-colour terminal formatter.
The Lab colour space is used to map RGB values to the most appropriate index colour.
var Tokens = Register("tokens", chroma.FormatterFunc(func(w io.Writer, s *chroma.Style, it chroma.Iterator) error { for t := it(); t != chroma.EOF; t = it() { if _, err := fmt.Fprintln(w, t.GoString()); err != nil { return err } } return nil }))
Tokens formatter outputs the raw token structures.
Functions ¶
func Get ¶
func Get(name string) chroma.Formatter
Get formatter by name.
If the given formatter is not found, the Fallback formatter will be returned.
func Names ¶
func Names() []string
Names of registered formatters.
func Register ¶
func Register(name string, formatter chroma.Formatter) chroma.Formatter
Register a named formatter.
Source Files ¶
api.go json.go tokens.go tty_indexed.go tty_truecolour.go
Directories ¶
Path | Synopsis |
---|---|
formatters/html | |
formatters/svg | Package svg contains an SVG formatter. |
- Version
- v2.16.0 (latest)
- Published
- Apr 3, 2025
- Platform
- darwin/amd64
- Imports
- 9 packages
- Last checked
- 4 hours ago –
Tools for package owners.