LinuxCommandLibrary

highlight

Highlight source code syntax

TLDR

Produce a complete HTML document from a source code file

$ highlight [[-o|--out-format]] [html] [[-s|--style]] [theme_name] [[-S|--syntax]] [language] [path/to/source_code]
copy

Produce an HTML fragment, suitable for inclusion in a larger document
$ highlight [[-o|--out-format]] [html] [[-f|--fragment]] [[-S|--syntax]] [language] [source_file]
copy

Inline the CSS styling in every tag
$ highlight [[-o|--out-format]] [html] --inline-css [[-S|--syntax]] [language] [source_file]
copy

List all supported languages, themes, or plugins
$ highlight --list-scripts [langs|themes|plugins]
copy

Print a CSS stylesheet for a theme
$ highlight [[-o|--out-format]] [html] --print-style [[-s|--style]] [theme_name] [[-S|--syntax]] [language] --stdout
copy

SYNOPSIS

highlight [-i input-file] [-o output-file] [options]... [files]

PARAMETERS

-i, --input=FILE
    Specify input file (default: stdin)

-o, --output-file=FILE
    Specify output file (default: stdout or derived from input)

--out-format=FORMAT
    Output format: html, xterm256, truecolor, ansi, bbcode, svg, latex, tex, rtf (default: xterm256)

-s, --style=STYLE
    Style/theme file without .sty extension (default: pablo)

--line-number[=WIDTH]
    Show line numbers (default width: 5)

--line-number-ref[=WIDTH]
    Include original line numbers as reference

-c, --colour-date=timestamp
    Set modification date for HTML output

-H, --header
    Print file header

-F, --fragment
    Omit HTML header/footer (fragment only)

-V, --version
    Display version info

-h, --help
    Show help

--list-languages[=LANG]
    List supported languages

--list-styles[=SCRIPT]
    List available styles

--print-style[=OUTFILE]
    Print selected style definition

-d, --debug
    Enable debug mode

--force
    Overwrite output files

--no-warnings
    Suppress warnings

--src-lang=LANG
    Force source language

--gen-version
    Output version for generated files

DESCRIPTION

highlight is a powerful command-line tool for syntax highlighting source code and prose in over 200 languages. It reads input from files or stdin, applies highlighting rules from language definition files (.lang), and outputs formatted text in various styles to stdout or files.

Key features include:
Automatic language detection based on file extension or content.
Rich output formats: ANSI (xterm256, truecolor), HTML, SVG, LaTeX, TeX, BBCode.
Customizable styles via theme files (.sty).
• Line numbering, anchors, and inclusion of original line numbers.
• Support for filters, output separators, and font embedding.

Ideal for terminal viewing (highlight foo.c | less -R), generating web docs, or typesetting. It excels in piping outputs and integrates with pagers or editors for colored code display.

CAVEATS

Performance slows on very large files (>1MB); requires langdef/style files (install via package manager); terminal must support ANSI colors for best results; some formats need additional tools (e.g., ImageMagick for SVG).

INSTALLATION

Most distros: apt install highlight, dnf install highlight, brew install highlight. Includes langdefs and styles.

EXAMPLES

highlight *.c (terminal ANSI)
highlight -O html --style dark file.py > out.html (HTML)
highlight -l --out-format=latex foo.tex | pdflatex - (LaTeX)
find . -name '*.cpp' | xargs highlight -O xterm256 | less -R (batch)

CONFIGURATION

Langdefs in /usr/share/source-highlight/; styles in same dir. Customize with --print-style > my.sty then edit.

HISTORY

Developed by Andre Weinberg (2002) as part of GNU source-highlight project; maintained by Lorenzo Bettini since 2006. Evolved from simple Perl highlighter to feature-rich C++ tool supporting modern formats like truecolor.

SEE ALSO

source-highlight(1), bat(1), most(1)

Copied to clipboard