highlighter

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoLexer = errors.New("no lexer for supplied language")
)

Functions

This section is empty.

Types

type Highlighter

type Highlighter struct {
	// contains filtered or unexported fields
}

Highlighter is a wrapper for the chroma library that allows for line by line and substring highlighting.

func NewHighlighter

func NewHighlighter(lang string, lines []string, style *chroma.Style) (*Highlighter, error)

NewHighlighter returns a newly configured instance of Highlighter.

func (*Highlighter) CSS

func (h *Highlighter) CSS() (string, error)

CSS returns the formatted CSS classes for the chroma highlighting without being wrapped in <style> tags.

func (*Highlighter) HighlightLine

func (h *Highlighter) HighlightLine(line int) (string, error)

HighlightLine highlights the specified line number from the sources lines that were provided to the Highlighter instance.

func (*Highlighter) HighlightLines

func (h *Highlighter) HighlightLines(start, end int) ([]string, error)

HighlightLines calls HighlightLine over a range of lines and returns a list of the results.

func (*Highlighter) HighlightReplacedSubstr

func (h *Highlighter) HighlightReplacedSubstr(replacement string, line, start, end int, context bool) (string, error)

HighlightReplacedSubstr replaces the specified substring in the line with the newly provided string. It then highlights and returns the specified substring of a given line. If the context value is set to true, the Highlighter will highlight the whole line and then identify and return the specified substring HTML elements.

func (*Highlighter) HighlightSubstr

func (h *Highlighter) HighlightSubstr(line, start, end int, context bool) (string, error)

HighlightSubstr highlights and returns the specified substring of a given line. If the context value is set to true, the Highlighter will highlight the whole line and then identify and return the specified substring HTML elements.

func (*Highlighter) Lang

func (h *Highlighter) Lang() string

Lang returns the highlighters language

func (*Highlighter) Style

func (h *Highlighter) Style() *chroma.Style

Style returns the highlighters chroma style

Jump to

Keyboard shortcuts

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