package html
Import Path
github.com/alecthomas/chroma/v2/formatters/html (on go.dev)
Dependency Relation
imports 9 packages, and imported by one package
Involved Source Files
html.go
Package-Level Type Names (total 3)
Formatter that generates HTML.
// Exported field to detect when classes are being used
(*Formatter) Format(w io.Writer, style *chroma.Style, iterator chroma.Iterator) (err error)
WriteCSS writes CSS style definitions (without any surrounding HTML).
Rules are scoped by the style's mode (eg. ".chroma.dark") so that CSS
generated from a light and dark style can be combined without conflict.
To support dynamic theme switching, call WriteCSS with both styles,
concatenate the output, and toggle the wrapper's mode class (added
automatically by Format) at runtime. Tokens that one theme leaves
unstyled fall back to that theme's ".chroma.<mode>" text/background
via the CSS cascade; pass WithAllClasses(true) if you need every
token's rule materialised explicitly for both themes.
*Formatter : github.com/alecthomas/chroma/v2.Formatter
func New(options ...Option) *Formatter
Option sets an option of the HTML formatter.
func BaseLineNumber(n int) Option
func ClassPrefix(prefix string) Option
func HighlightLines(ranges [][2]int) Option
func InlineCode(b bool) Option
func LineNumbersInTable(b bool) Option
func PreventSurroundingPre(b bool) Option
func Standalone(b bool) Option
func TabWidth(width int) Option
func WithAllClasses(b bool) Option
func WithClasses(b bool) Option
func WithCSSComments(b bool) Option
func WithCustomCSS(css map[chroma.TokenType]string) Option
func WithLineNumbers(b bool) Option
func WithLinkableLineNumbers(b bool, prefix string) Option
func WithModeClasses(b bool) Option
func WithPreWrapper(wrapper PreWrapper) Option
func WrapLongLines(b bool) Option
func New(options ...Option) *Formatter
PreWrapper defines the operations supported in WithPreWrapper.
End is called to write the end </pre> element.
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.
func WithPreWrapper(wrapper PreWrapper) Option
Package-Level Functions (total 19)
BaseLineNumber sets the initial number to start line numbering at. Defaults to 1.
ClassPrefix sets the CSS class prefix.
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.
InlineCode creates inline code wrapped in a code tag.
LineNumbersInTable will, when combined with WithLineNumbers, separate the line numbers
and code in table td's, which make them copy-and-paste friendly.
New HTML formatter.
PreventSurroundingPre prevents the surrounding pre tags around the generated code.
Standalone configures the HTML formatter for generating a standalone HTML document.
StyleEntryToCSS converts a chroma.StyleEntry to CSS attributes.
TabWidth sets the number of characters for a tab. Defaults to 8.
WithAllClasses disables an optimisation that omits redundant CSS classes.
WithClasses emits HTML using CSS classes, rather than inline styles.
WithCSSComments adds prefixe comments to the css classes. Defaults to true.
WithCustomCSS sets user's custom CSS styles.
WithLineNumbers formats output with line numbers.
WithLinkableLineNumbers decorates the line numbers HTML elements with an "id"
attribute so they can be linked.
WithModeClasses adds the style's mode (eg. "light" or "dark") as a CSS
class on wrapper elements and scopes WriteCSS rules by mode. This enables
combining light and dark stylesheets and switching themes at runtime.
WithPreWrapper allows control of the surrounding pre tags.
WrapLongLines wraps long lines.
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |