← 返回命令列表

Linux command

chroma 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Highlight source file

chroma [file.go]

Specify language

chroma -l python [file.py]

HTML output

chroma --html [file.js] > [output.html]

List available lexers

chroma --list

Use specific style

chroma -s monokai [file.rb]

HTML with inline styles

chroma --html --html-inline-styles [file.c]

说明

chroma is a general-purpose syntax highlighter supporting approximately 250 languages. It converts source code to syntax-highlighted HTML, ANSI-colored terminal output, SVG, and other formats. The tool is based on the Pygments highlighting engine but reimplemented in Go for speed and easy embedding. It supports numerous color styles (monokai, dracula, github, etc.) and can autodetect the language from filenames and content. Chroma is also available as a Go library, used by tools like Hugo for code highlighting.

参数

-l, --lexer _name_
Lexer to use (default: autodetect)
-s, --style _name_
Highlighting style
-f, --formatter _name_
Output formatter: terminal, terminal256, terminal16m, html
--html
Enable HTML mode
--html-only
Output HTML fragment only
--html-inline-styles
Inline CSS styles (no classes)
--list
List lexers, styles, formatters
--fail
Exit with status 1 if lexer not found

FAQ

What is the chroma command used for?

chroma is a general-purpose syntax highlighter supporting approximately 250 languages. It converts source code to syntax-highlighted HTML, ANSI-colored terminal output, SVG, and other formats. The tool is based on the Pygments highlighting engine but reimplemented in Go for speed and easy embedding. It supports numerous color styles (monokai, dracula, github, etc.) and can autodetect the language from filenames and content. Chroma is also available as a Go library, used by tools like Hugo for code highlighting.

How do I run a basic chroma example?

Run `chroma [file.go]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -l, --lexer _name_ do in chroma?

Lexer to use (default: autodetect)