highlight

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package highlight wires Chroma syntax highlighting into the Markdown pipeline and generates the matching token stylesheet, so the parser and the template layer agree on a single theme without either owning Chroma.

Index

Constants

View Source
const (
	// ThemeNone is the config value that turns syntax highlighting off while
	// keeping the code block panel style.
	ThemeNone = "none"

	// DefaultTheme is the theme used when the configured one is unknown to
	// Chroma, and the one config.Default() ships with.
	DefaultTheme = "monokai"

	// MonoFallbacks is the font stack appended after the configured code font,
	// so blocks still render as monospace when that font cannot be loaded.
	MonoFallbacks = `ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace`
)

Variables

This section is empty.

Functions

func CSS

func CSS(cfg config.CodeConfig) string

CSS returns the Chroma token stylesheet for cfg's theme, one rule per line, or "" when highlighting is off.

func Enabled

func Enabled(cfg config.CodeConfig) bool

Enabled reports whether cfg asks for syntax highlighting.

func Extension

func Extension(cfg config.CodeConfig) goldmark.Extender

Extension returns the goldmark extension that highlights fenced code blocks, or nil when highlighting is off. Token colors are emitted as classes rather than inline styles so CSS from the config keeps the last word.

func Palette

func Palette(cfg config.CodeConfig) (background, foreground string)

Palette returns the code block background and foreground colors: explicit config values win, then the theme's own colors, then the fallbacks.

With the panel off, the theme's own text color is dropped unless it was set explicitly: it was picked to sit on the theme's background, not on the page.

func PanelDisabled

func PanelDisabled(cfg config.CodeConfig) bool

PanelDisabled reports whether cfg turns the filled panel off, leaving code on the page background.

func Style

func Style(cfg config.CodeConfig) *chroma.Style

Style resolves cfg.Theme to a Chroma style, warning and falling back to DefaultTheme when the name is unknown. Returns nil when highlighting is off.

func Themes

func Themes() []string

Themes returns the sorted names of every theme Chroma can render.

Types

This section is empty.

Jump to

Keyboard shortcuts

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