syntax

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package syntax detects source languages, highlights code, and finds foldable function and class blocks.

Index

Constants

View Source
const MaxHighlightLines = 8000

MaxHighlightLines caps the work done for one file. Longer files stay plain.

Variables

This section is empty.

Functions

func Highlight

func Highlight(lang string, lines []string) (out [][]Span, ok bool)

Highlight tokenises lines with the lexer named lang. The result is one slice of spans per source line. ok is false when the language is unknown, the file is too long, or tokenising failed.

Types

type Block

type Block struct {
	// Start is the 0-based line that opens the block.
	Start int
	// End is the 0-based last line of the block, inclusive.
	End int
	// Kind is "func" or "type".
	Kind string
}

Block is a foldable range of source lines.

func BlockAt

func BlockAt(blocks []Block, line int) (Block, bool)

BlockAt returns the innermost block that contains line.

func Outline

func Outline(lang Language, lines []string) []Block

Outline returns the foldable blocks in lines. It understands Go, Python, and the brace languages named in Language.Family.

type Language

type Language struct {
	// Name is the chroma lexer name, for example "Go" or "Python".
	Name string
	// Family groups languages that share a folding strategy: "go", "python",
	// "brace", or "" when the language has no folding support.
	Family string
}

Language is a detected source language.

func Detect

func Detect(name, content string) Language

Detect picks a lexer from the file name first, then from the content.

func (Language) Detected

func (l Language) Detected() bool

Detected reports whether a language was found.

type Span

type Span struct {
	Text   string
	Colour string
	Bold   bool
	Italic bool
}

Span is a run of source text that shares one colour.

Jump to

Keyboard shortcuts

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