formatters

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT, OFL-1.1 Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// NoOp formatter.
	NoOp = Register("noop", chroma.FormatterFunc(func(w io.Writer, s *chroma.Style, iterator iter.Seq[chroma.Token]) error {
		for t := range 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)))
)
View Source
var Fallback = NoOp

Fallback formatter.

View Source
var JSON = Register("json", chroma.FormatterFunc(func(w io.Writer, s *chroma.Style, it iter.Seq[chroma.Token]) error {
	if _, err := fmt.Fprintln(w, "["); err != nil {
		return err
	}
	i := 0
	for t := range 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.

View Source
var MIRC100 = Register("mirc100", chroma.FormatterFunc(mIRCExtendedColorFormatter))

mIRC extended color codes

View Source
var MIRC16m = Register("mirc16m", chroma.FormatterFunc(mIRCHexColorFormatter))

mIRC16m is a true-colour formatter.

View Source
var TTY = Register("terminal", TTY8)

TTY is the default terminal formatter, an alias for TTY8.

View Source
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.

Each RGB colour is mapped to the nearest index colour, as measured by Colour.Distance.

View Source
var TTY16m = Register("terminal16m", chroma.FormatterFunc(trueColourFormatter))

TTY16m is a true-colour terminal formatter.

View Source
var TTY256 = Register("terminal256", indexedTTYFormatter(ttyTables[256]))

TTY256 is a 256-colour terminal formatter.

Each RGB colour is mapped to the nearest index colour, as measured by Colour.Distance.

View Source
var TTY8 = Register("terminal8", indexedTTYFormatter(ttyTables[8]))

TTY8 is an 8-colour terminal formatter.

Each RGB colour is mapped to the nearest index colour, as measured by Colour.Distance.

View Source
var Tokens = Register("tokens", chroma.FormatterFunc(func(w io.Writer, s *chroma.Style, it iter.Seq[chroma.Token]) error {
	for t := range 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 Lookup

func Lookup(name string) (chroma.Formatter, bool)

Lookup a named formatter, returning false if not found.

func Names

func Names() []string

Names of registered formatters.

func Register

func Register(name string, formatter chroma.Formatter) chroma.Formatter

Register a named formatter.

Not safe to call concurrently with other functions in this package; register all formatters at init time.

Types

This section is empty.

Directories

Path Synopsis
Package svg contains an SVG formatter.
Package svg contains an SVG formatter.

Jump to

Keyboard shortcuts

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