highlight1
A universal sourcecode to formatted text converter
Usage
highlight [OPTIONS] ...
[FILES] ...
Overview
Highlight converts sourcecode to HTML, XHTML, RTF, ODT, LaTeX, TeX, BBCode, Pango markup, SVG, XTERM or ANSI escape sequences. There are several colour themes available. Highlight recognizes keywords, numbers, strings, comments, symbols and preprocessor directives. It supports about 180 programming languages, which are defined in Lua scripts.
It's easily possible to enhance highlight's database of programming languages and colour themes. See the README file for details.
Options
-
-B, --batch-recursive=<wildcard> -
convert all files matching the wildcard (uses recursive search)
-
-D, --data-dir=<path> -
set path to highlight data directory
-
--config-file=<file> -
set path to a lang or theme file
-
-h, --help[=topic] -
print this help or a topic description <topic> = [syntax, theme, plugin, config]
-
-i, --input=<file> -
name of input file
-
-o, --output=<file> -
name of output file
-d,--outdir=<output directory>-
name of output directory
-
-P, --progress -
print progress bar in batch mode
-
-S, --syntax=<type|path> -
set type of source code, necessary if input file suffix is missing. The syntax may also be defined as path of the language file.
-
--syntax-by-name=<name> -
specify type of source code by given name. Will not read a file of this name, useful for stdin and to determine the syntax of the file before piping its content to highlight. This option overrides --syntax.
-
--syntax-supported -
test if the given syntax can be loaded and print the result (assumes -S or --syntax-by-name)
-
-v, --verbose -
print debug info to stderr; repeat to show more information
-
-q, --quiet -
suppress progress info in batch mode
-
--force[=syntax] -
generate output if input syntax is unknown. The fallback syntax may be set here, Plain Text is default.
-
--list-scripts=<type> -
list installed scripts <type> = [langs, themes, plugins]
-
--list-cat=<categories> -
filter the scripts by the given categories (example: --list-cat='source;script')
-
--max-size=<size> -
set maximum input file size (examples: 512M, 1G; default: 256M)
-
--skip-leading-cols=<num> -
output the first num columns of each line unhighlighted; the columns are kept out of the parser, so quotes or comment delimiters within them cannot alter the highlighting of the remaining code (example: output of hg or svn annotate)
-
--plug-in=<script> -
execute Lua plug-in script; repeat option to apply multiple plug-ins
-
--plug-in-param -
set plug-in input parameter. This might be an input file name (ie. 'tags').
-
--print-config -
print path configuration
-
--print-style -
print stylesheet only (see --style-outfile)
-
--skip=<list> -
ignore listed unknown file types (example: --skip='bak;c~;h~')
-
--stdout -
output to stdout (batch mode, --print-style)
-
--validate-input -
test if input is a valid text file
-
--service-mode -
run in service mode, not stopping until signaled
-
--version -
print version and copyright info
Options
-
-O, --out-format=<format> -
output file in given format <format>=[html, xhtml, latex, tex, rtf, odt, ansi, xterm256, truecolor, bbcode, pango, svg]
-
-c, --style-outfile=<file> -
name of style definition file
-
-T, --doc-title -
document title
-
-e, --style-infile=<file> -
name of file to be included in style-outfile
-
-f, --fragment -
omit header and footer of the output document (see --keep-injections)
-
-F, --reformat=<style> -
reformat output in given style. <style>=[allman, gnu, google, horstmann, java, kr, linux, lisp, mozilla, otbs, pico, vtk, ratliff, stroustrup, webkit, whitesmith]
-
-I, --include-style -
include style definition in output
-
-J, --line-length=<num> -
line length before wrapping (see -V, -W)
-
-j, --line-number-length=<num> -
line number length incl. left padding. Default length: 5
-
-k, --font=<font> -
set font (specific to output format)
-
-K, --font-size=<num?> -
set font size (specific to output format)
-
-l, --line-numbers -
print line numbers in output file
-
-m, --line-number-start=<cnt> -
start line numbering with cnt (assumes -l)
-
--line-range=<start-end> -
output only lines from number <start> to <end>
-
--indent-guides -
draw a guide in the leading whitespace of every indentation level. Blank lines inside a block take the indentation of the next line which contains code. The guides use the IndentGuide theme element, or a dimmed default if the theme does not define one (plain ansi output always uses the dimmed default); implies -t 4 if no tab width was set
-s,--style=<style name|path>-
set highlighting style (theme). Add 'base16/' prefix to use a Base16 theme. The theme may also be defined as path of the theme file.
-t--replace-tabs=<num>-
replace tabs by num spaces
-
-u, --encoding=<enc> -
set output encoding which matches input file encoding; omit encoding information if set to "NONE"
-
-V, --wrap-simple -
wrap lines after 80 (default) characters without indenting function parameters and statements.
-
-W, --wrap -
wrap lines after 80 (default) characters (use with caution).
-
-z, --zeroes -
fill leading space of line numbers with zeroes
-
--isolate -
output each syntax token in separate tags (verbose output)
-
--keep-injections -
output plug-in header and footer injections in spite of -f
-
--kw-case=<upper|lower|capitalize> -
output all keywords in given case if language is not case sensitive
-
--no-trailing-nl[=mode] -
omit trailing newline. If mode is "empty-file", omit only for empty input
-
--no-version-info -
omit version info comment
-
--wrap-no-numbers -
omit line numbers of wrapped lines (assumes -l)
Options
-
-a, --anchors -
attach anchors to line numbers (HTML only)
-
-y, --anchor-prefix=<str> -
set anchor name prefix
-
-N, --anchor-filename -
use input file name as anchor name
-
-C, --print-index -
print index file with links to all output files
-
-n, --ordered-list -
print lines as ordered list items
-
--class-name=<str> -
set CSS class name prefix; omit class name if set to "NONE"
-
--inline-css -
output CSS within each tag (verbose output)
-
--enclose-pre -
enclose fragmented output with pre tag (assumes -f)
Options
-
-b, --babel -
disable Babel package shorthands
-
-r, --replace-quotes -
replace double quotes by \dq
-
--beamer -
adapt output for the Beamer package
-
--pretty-symbols -
improve appearance of brackets and other symbols
Options
-
--page-color -
include page color attributes
-
-x, --page-size=<size> -
set page size, <size>=[a3, a4, a5, b4, b5, b6, letter]
-
--char-styles -
include character stylesheets
Options
-
--height=<h> -
set image height (units allowed)
-
--width=<w> -
set image size (see --height)
Terminal escape output options (XTERM256 or truecolor)
--canvas[=width]-
set background colour padding (default: 80)
Options
-
--ls-profile=<server> -
load LSP configuration from lsp.conf
-
--ls-delay=<ms> -
set server initialization delay in milliseconds
-
--ls-exec=<bin> -
set server executable name
-
--ls-option=<option> -
set server CLI option (can be repeated)
-
--ls-hover -
execute hover requests (HTML output only)
-
--ls-semantic -
query server for semantic token types (requires LSP 3.16)
-
--ls-syntax=<lang> -
set syntax which is understood by the server
-
--ls-syntax-error -
retrieve syntax error information (assumes --ls-hover or --ls-semantic)
-
--ls-workspace=<dir> -
set workspace directory to initialize the server
-
--ls-legacy -
do not require a server capabilities response
Env variables
Highlight recognizes these variables:
HIGHLIGHT_DATADIR
|
sets the path to highlight's configuration scripts |
|---|---|
HIGHLIGHT_OPTIONS
|
may contain command line options, but no input file paths. |
Hints
If no in- or output files are specified, stdin and stdout will be used for in- or output. Reading from stdin can also be triggered by the '-' option.
Default output format: xterm256 or truecolor if appropriate, HTML otherwise.
Style definitions are stored in highlight.css (HTML, XHTML, SVG) or highlight.sty (LaTeX, TeX) if neither -c nor -I is given. For CSS, definitions are stored in the output document header with -I, if -f is also given there will be no style definitions.
Reformatting code (-F) will only work with C, C++, C# and Java input files.
LSP features require absolute input paths and disable reformatting (-F).
Files
The configuration files are stored in /usr/share/highlight/. Language definitions, themes and plugins are located in subdirectories.
Documentation files are stored in /usr/share/doc/highlight/, configuration files in /etc/highlight/.
See README how to install own scripts in the home directory.
Examples
Single file conversion:
highlight -o hello.html -i hello.c
highlight -o hello.html hello.c
highlight -o hello.html -S c < hello.c
highlight -S c < hello.c > hello.html
Note that a file highlight.css is created in the current directory.
Batch file processing:
highlight --out-format=xhtml -B '*.cpp' -d /home/you/html_code/
converts all *.cpp files in the current directory and its subdirectories to xhtml files, and stores the output in /home/you/html_code.
highlight --out-format=latex * -d /home/you/latex_code/
converts all files to LaTeX, stored in /home/you/latex_code/.
Use --quiet to improve performance of batch file processing (recommended for usage in shell scripts).
Use highlight --out-format=xterm256 <yourfile> | less -R to display a source file in a terminal.
Run highlight --list-scripts=langs to see all supported syntax types.
Releases
12 releases since Debian 3.1 (Sarge); the text changed 8 times.
--anchor-filename since Debian 6.0 (Squeeze);
--anchor-prefix since Debian 6.0 (Squeeze);
--babel since Debian 4.0 (Etch);
--beamer since Debian 10 (Buster);
--char-styles since Debian 6.0 (Squeeze);
--class-name since Debian 6.0 (Squeeze);
--config-file since Debian 7 (Wheezy);
--doc-title since Debian 4.0 (Etch);
--enclose-pre since Debian 6.0 (Squeeze);
--encoding since Debian 4.0 (Etch);
--font since Debian 4.0 (Etch);
--font-size since Debian 4.0 (Etch);
--force since Debian 4.0 (Etch);
--height since Debian 6.0 (Squeeze);
--include-style since Debian 4.0 (Etch);
--indent-guides since Arch Linux 2026-11-01;
--inline-css since Debian 6.0 (Squeeze);
--isolate since Debian 13 (Trixie);
--keep-injections since Debian 10 (Buster);
--kw-case since Debian 6.0 (Squeeze);
--line-length since Debian 6.0 (Squeeze);
--line-number-length since Debian 6.0 (Squeeze);
--line-number-start since Debian 4.0 (Etch);
--line-numbers since Debian 7 (Wheezy);
--line-range since Debian 13 (Trixie);
--list-cat since Debian 13 (Trixie);
--list-scripts since Debian 8 (Jessie);
--ls-delay since Debian 13 (Trixie);
--ls-exec since Debian 13 (Trixie);
--ls-hover since Debian 13 (Trixie);
--ls-legacy since Debian 13 (Trixie);
--ls-option since Debian 13 (Trixie);
--ls-profile since Debian 13 (Trixie);
--ls-semantic since Debian 13 (Trixie);
--ls-syntax since Debian 13 (Trixie);
--ls-syntax-error since Debian 13 (Trixie);
--ls-workspace since Debian 13 (Trixie);
--max-size since Debian 13 (Trixie);
--no-trailing-nl since Debian 6.0 (Squeeze);
--no-version-info since Debian 10 (Buster);
--ordered-list since Debian 4.0 (Etch);
--out-format since Debian 7 (Wheezy);
--page-color since Debian 10 (Buster);
--page-size since Debian 4.0 (Etch);
--plug-in since Debian 7 (Wheezy);
--plug-in-param since Debian 10 (Buster);
--pretty-symbols since Debian 6.0 (Squeeze);
--print-config since Debian 4.0 (Etch);
--print-style since Debian 7 (Wheezy);
--reformat since Debian 4.0 (Etch);
--service-mode since Debian 13 (Trixie);
--skip since Debian 6.0 (Squeeze);
--skip-leading-cols since Arch Linux 2026-11-01;
--stdout since Debian 10 (Buster);
--style-infile since Debian 4.0 (Etch);
--style-outfile since Debian 4.0 (Etch);
--syntax-by-name since Debian 13 (Trixie);
--syntax-supported since Debian 13 (Trixie);
--validate-input since Debian 6.0 (Squeeze);
--width since Debian 6.0 (Squeeze);
--wrap-no-numbers since Debian 8 (Jessie);
-J since Debian 6.0 (Squeeze);
-K since Debian 4.0 (Etch);
-N since Debian 6.0 (Squeeze);
-O since Debian 7 (Wheezy);
-T since Debian 7 (Wheezy);
-b since Debian 4.0 (Etch);
-j since Debian 4.0 (Etch);
-k since Debian 4.0 (Etch);
-m since Debian 4.0 (Etch);
-n since Debian 6.0 (Squeeze);
-u since Debian 4.0 (Etch);
-x since Debian 4.0 (Etch);
-y since Debian 6.0 (Squeeze).
--add-config-dir until Debian 7 (Wheezy);
--add-data-dir until Debian 6.0 (Squeeze);
--css until Debian 12 (Bookworm);
--css-infile until Debian 3.1 (Sarge);
--css-outfile until Debian 3.1 (Sarge);
--ctags-file until Debian 7 (Wheezy);
--delim-cr until Debian 12 (Bookworm);
--doc until Debian 12 (Bookworm);
--failsafe until Debian 12 (Bookworm);
--fop-compatible until Debian 3.1 (Sarge);
--format-style until Debian 3.1 (Sarge);
--help-int until Debian 3.1 (Sarge);
--help-lang until Debian 5.0 (Lenny);
--include-css until Debian 3.1 (Sarge);
--line-number until Debian 12 (Bookworm);
--line-number-ref until Debian 12 (Bookworm);
--line-number-width until Debian 5.0 (Lenny);
--linenumbers until Debian 6.0 (Squeeze);
--list-langs until Debian 9 (Stretch);
--list-themes until Debian 9 (Stretch);
--no-doc until Debian 12 (Bookworm);
--output-dir until Debian 12 (Bookworm);
--plug-in-read until Debian 9 (Stretch);
--src-lang until Debian 12 (Bookworm);
--start-nested until Debian 12 (Bookworm);
--tab until Debian 12 (Bookworm);
-E until Debian 6.0 (Squeeze);
-H until Debian 5.0 (Lenny);
-d until Debian 6.0 (Squeeze);
-g until Debian 3.1 (Sarge);
-p until Debian 9 (Stretch);
-t until Debian 12 (Bookworm);
-w until Debian 9 (Stretch).