LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

highlight

converts source code to formatted output with syntax highlighting

TLDR

Highlight source code
$ highlight [file.py]
copy
Output as HTML
$ highlight -O html [file.py] > [file.html]
copy
Output as ANSI (terminal)
$ highlight -O ansi [file.py]
copy
Specify language
$ highlight --syntax=[python] [file]
copy
Use specific theme
$ highlight --style=[molokai] [file.py]
copy
List supported languages
$ highlight --list-scripts=langs
copy
List available themes
$ highlight --list-scripts=themes
copy

SYNOPSIS

highlight [options] [files...]

DESCRIPTION

highlight converts source code to formatted output with syntax highlighting. It supports over 250 programming and markup languages and can output to HTML, XHTML, RTF, ODT, TeX, LaTeX, SVG, Pango, BBCode, and ANSI/terminal escape sequences (including 256-color and truecolor).The tool is useful for documentation, presentations, and generating printable source listings with proper syntax coloring.

PARAMETERS

-O, --out-format format

Output format: html, xhtml, latex, tex, rtf, odt, ansi, xterm256, truecolor, bbcode, pango, svg.
-S, --syntax lang
Specify source language, needed if it can't be guessed from the file suffix.
-s, --style name
Color theme (add a "base16/" prefix to use a Base16 theme).
-l, --line-numbers
Include line numbers.
-i, --input file
Input file.
-o, --output file
Output file.
--list-scripts type
List langs, themes, or plugins.
-f, --fragment
Omit document headers.
--inline-css
Embed CSS in HTML.
-a, --anchors
Attach anchors to line numbers (HTML only).
-B, --batch-recursive wildcard
Convert all files matching the wildcard, recursively.
--stdout
In batch mode, write output to stdout instead of files.
-t, --replace-tabs num
Replace tabs with the given number of spaces.
-u, --encoding enc
Set output encoding to match the input file's encoding.
--config-file file
Path to a custom language definition or theme file.

INSTALL

sudo apt install highlight
copy
sudo dnf install highlight
copy
sudo pacman -S highlight
copy
sudo apk add highlight
copy
sudo zypper install highlight
copy
brew install highlight
copy
nix profile install nixpkgs#highlight
copy

CAVEATS

Language detection may need hints. Theme appearance varies by output format. Some languages have limited support.

HISTORY

highlight was created by Andre Simon as a universal source code highlighter. It has been actively developed since 2002, continuously adding language support and output formats.

SEE ALSO

RESOURCES

Copied to clipboard
Kai