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 [options] [file...]

PARAMETERS

-s LANG, --syntax=LANG
    Specifies the input programming language or file type for highlighting (e.g., c++, python, java).

-O FMT, --out-format=FMT
    Defines the output format, such as html, rtf, tex, ansi, or svg.

-t NAME, --theme=NAME
    Selects the color theme to apply for highlighting (e.g., solarized-dark, default).

-o FILE, --output=FILE
    Writes the highlighted output to the specified FILE instead of standard output.

-l, --line-numbers
    Includes line numbers in the output.

--list-themes
    Displays a list of all available color themes.

--list-languages
    Shows a list of all supported programming languages and file formats.

DESCRIPTION

highlight is a versatile command-line utility designed to syntax highlight source code, configuration files, and other structured text.

It supports a wide array of programming languages and markup formats. Users can output the highlighted text to various formats, including HTML, RTF, LaTeX, SVG, and ANSI escape sequences for terminal display.

This makes it invaluable for generating beautiful code snippets for documentation, web pages, presentations, or for simply improving readability directly in the terminal. It can automatically detect the input language or be explicitly told which language to use. Its extensive customization options allow users to choose color themes, control font sizes, and manage line numbering, among other features.

CAVEATS

While highlight is robust, its automatic language detection can sometimes be inaccurate for very short snippets or files without clear language indicators. Large files might also impact performance. Customizing themes and output styles extensively requires understanding its configuration files, which can be somewhat intricate initially.

CONFIGURATION AND CUSTOMIZATION

highlight is highly customizable through configuration files typically located in /usr/share/highlight/ or ~/.highlight/. These files define themes, language definitions, and general settings, allowing users to fine-tune virtually every aspect of the highlighting process, including adding new languages or modifying existing ones.

HISTORY

The highlight utility was initially developed by Andre Simon, with its first release dating back to 2004. It has been consistently maintained and expanded over the years, growing its support for a vast number of programming languages, output formats, and customization features. Its continued development reflects its utility as a standalone, powerful command-line solution for syntax highlighting.

SEE ALSO

bat(1), pygmentize(1), source-highlight(1), cat(1)

Copied to clipboard