Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
chroma
✓ github.com/alecthomas/chroma
Syntax highlights Go source code for terminal output
package main
import (
"fmt"
"github.com/alecthomas/chroma"
"github.com/alecthomas/chroma/lexers"
"github.com/alecthomas/chroma/formatters"
"github.com/alecthomas/chroma/styles"
)
func main() {
code := `package main
func main() {
println("hello")
}`
lexer := lexers.Get("go")
formatter := formatters.Get("terminal")
style := styles.Get("monokai")
highlighted, _ := formatter.Format(nil, style, lexer.Tokenise(nil, code))
fmt.Println(highlighted)
}
Debug
Known issues
No known issues recorded.
Upgrade
Version history
0.10.0latest on pkg.go.dev
Audit
Dependencies
No dependency data recorded yet.