Version: v0.10.0 Latest Latest

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

Go to latest
Published: Jan 12, 2022 License: MIT Imports: 6 Imported by: 231




This section is empty.


This section is empty.


func StyleEntryToCSS

func StyleEntryToCSS(e chroma.StyleEntry) string

StyleEntryToCSS converts a chroma.StyleEntry to CSS attributes.


type Formatter

type Formatter struct {
	Classes bool // Exported field to detect when classes are being used
	// contains filtered or unexported fields

Formatter that generates HTML.

func New

func New(options ...Option) *Formatter

New HTML formatter.

func (*Formatter) Format

func (f *Formatter) Format(w io.Writer, style *chroma.Style, iterator chroma.Iterator) (err error)

func (*Formatter) WriteCSS

func (f *Formatter) WriteCSS(w io.Writer, style *chroma.Style) error

WriteCSS writes CSS style definitions (without any surrounding HTML).

type Option

type Option func(f *Formatter)

Option sets an option of the HTML formatter.

func BaseLineNumber

func BaseLineNumber(n int) Option

BaseLineNumber sets the initial number to start line numbering at. Defaults to 1.

func ClassPrefix

func ClassPrefix(prefix string) Option

ClassPrefix sets the CSS class prefix.

func HighlightLines

func HighlightLines(ranges [][2]int) Option

HighlightLines higlights the given line ranges with the Highlight style.

A range is the beginning and ending of a range as 1-based line numbers, inclusive.

func LineNumbersInTable added in v0.2.0

func LineNumbersInTable(b bool) Option

LineNumbersInTable will, when combined with WithLineNumbers, separate the line numbers and code in table td's, which make them copy-and-paste friendly.

func LinkableLineNumbers added in v0.7.1

func LinkableLineNumbers(b bool, prefix string) Option

LinkableLineNumbers decorates the line numbers HTML elements with an "id" attribute so they can be linked.

func PreventSurroundingPre added in v0.6.0

func PreventSurroundingPre(b bool) Option

PreventSurroundingPre prevents the surrounding pre tags around the generated code.

func Standalone

func Standalone(b bool) Option

Standalone configures the HTML formatter for generating a standalone HTML document.

func TabWidth

func TabWidth(width int) Option

TabWidth sets the number of characters for a tab. Defaults to 8.

func WithAllClasses added in v0.7.2

func WithAllClasses(b bool) Option

WithAllClasses disables an optimisation that omits redundant CSS classes.

func WithClasses

func WithClasses(b bool) Option

WithClasses emits HTML using CSS classes, rather than inline styles.

func WithLineNumbers

func WithLineNumbers(b bool) Option

WithLineNumbers formats output with line numbers.

func WithPreWrapper added in v0.7.0

func WithPreWrapper(wrapper PreWrapper) Option

WithPreWrapper allows control of the surrounding pre tags.

func WrapLongLines added in v0.10.0

func WrapLongLines(b bool) Option

WrapLongLines wraps long lines.

type PreWrapper added in v0.7.0

type PreWrapper interface {
	// Start is called to write a start <pre> element.
	// The code flag tells whether this block surrounds
	// highlighted code. This will be false when surrounding
	// line numbers.
	Start(code bool, styleAttr string) string

	// End is called to write the end </pre> element.
	End(code bool) string

PreWrapper defines the operations supported in WithPreWrapper.

Jump to

Keyboard shortcuts

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