Documentation
¶
Index ¶
- func StyleEntryToCSS(e chroma.StyleEntry) string
- type Formatter
- type Option
- 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 WithCSSComments(b bool) Option
- func WithClasses(b bool) Option
- func WithCustomCSS(css map[chroma.TokenType]string) Option
- func WithLineNumbers(b bool) Option
- func WithLinkableLineNumbers(b bool, prefix string) Option
- func WithPreWrapper(wrapper PreWrapper) Option
- func WrapLongLines(b bool) Option
- type PreWrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StyleEntryToCSS ¶
func StyleEntryToCSS(e chroma.StyleEntry) string
StyleEntryToCSS converts a chroma.StyleEntry to CSS attributes.
Types ¶
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 (*Formatter) WriteCSS ¶
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.
type Option ¶
type Option func(f *Formatter)
Option sets an option of the HTML formatter.
func BaseLineNumber ¶
BaseLineNumber sets the initial number to start line numbering at. Defaults to 1.
func HighlightLines ¶
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 InlineCode ¶ added in v2.2.0
InlineCode creates inline code wrapped in a code tag.
func LineNumbersInTable ¶
LineNumbersInTable will, when combined with WithLineNumbers, separate the line numbers and code in table td's, which make them copy-and-paste friendly.
func PreventSurroundingPre ¶
PreventSurroundingPre prevents the surrounding pre tags around the generated code.
func Standalone ¶
Standalone configures the HTML formatter for generating a standalone HTML document.
func WithAllClasses ¶
WithAllClasses disables an optimisation that omits redundant CSS classes.
func WithCSSComments ¶ added in v2.20.0
WithCSSComments adds prefixe comments to the css classes. Defaults to true.
func WithClasses ¶
WithClasses emits HTML using CSS classes, rather than inline styles.
func WithCustomCSS ¶
WithCustomCSS sets user's custom CSS styles.
func WithLineNumbers ¶
WithLineNumbers formats output with line numbers.
func WithLinkableLineNumbers ¶ added in v2.4.0
WithLinkableLineNumbers decorates the line numbers HTML elements with an "id" attribute so they can be linked.
func WithPreWrapper ¶
func WithPreWrapper(wrapper PreWrapper) Option
WithPreWrapper allows control of the surrounding pre tags.
type PreWrapper ¶
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.