package highlight

import "github.com/gohugoio/hugo/markup/highlight"

Package highlight provides code highlighting.

Index

Variables

var DefaultConfig = Config{

	Style:              "monokai",
	LineNoStart:        1,
	CodeFences:         true,
	NoClasses:          true,
	LineNumbersInTable: true,
	TabWidth:           4,
	WrapperClass:       "highlight",
}

Functions

func ApplyLegacyConfig

func ApplyLegacyConfig(cfg config.Provider, conf *Config) error

ApplyLegacyConfig applies legacy config from back when we had Pygments.

func WritePreStart

func WritePreStart(w io.Writer, language, styleAttr string)

Types

type Config

type Config struct {
	Style string

	// Enable syntax highlighting of fenced code blocks.
	CodeFences bool

	// The class or classes to use for the outermost element of the highlighted code.
	WrapperClass string

	// Use inline CSS styles.
	NoClasses bool

	// When set, line numbers will be printed.
	LineNos            bool
	LineNumbersInTable bool

	// When set, add links to line numbers
	AnchorLineNos bool
	LineAnchors   string

	// Start the line numbers from this value (default is 1).
	LineNoStart int

	// A space separated list of line numbers, e.g. “3-8 10-20”.
	Hl_Lines string

	// If set, the markup will not be wrapped in any container.
	Hl_inline bool

	// A parsed and ready to use list of line ranges.
	HL_lines_parsed [][2]int `json:"-"`

	// TabWidth sets the number of characters for a tab. Defaults to 4.
	TabWidth int

	GuessSyntax bool
}

type HighlightResult

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

HighlightResult holds the result of an highlighting operation.

func (HighlightResult) Inner

func (h HighlightResult) Inner() template.HTML

Inner returns the highlighted code without the wrapping <div>, <pre> and <code> tag, suitable for inline use.

func (HighlightResult) Wrapped

func (h HighlightResult) Wrapped() template.HTML

Wrapped returns the highlighted code wrapped in a <div>, <pre> and <code> tag.

type Highlighter

type Highlighter interface {
	Highlight(code, lang string, opts any) (string, error)
	HighlightCodeBlock(ctx hooks.CodeblockContext, opts any) (HighlightResult, error)
	hooks.CodeBlockRenderer
	hooks.IsDefaultCodeBlockRendererProvider
}

func New

func New(cfg Config) Highlighter

Source Files

config.go highlight.go

Directories

PathSynopsis
markup/highlight/chromalexers
Version
v0.144.2 (latest)
Published
Feb 19, 2025
Platform
linux/amd64
Imports
19 packages
Last checked
13 hours ago

Tools for package owners.