Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tree-sitter/tree-sitter/llms.txt

Use this file to discover all available pages before exploring further.

The highlight command runs syntax highlighting on an arbitrary file. It can output colors directly to your terminal using ANSI escape codes, or produce HTML.
tree-sitter highlight [OPTIONS] [PATHS]...
Aliases: hi For more information about syntax highlighting, see Syntax Highlighting.

Input Sources

File Paths

Pass file paths directly:
tree-sitter highlight example.js

Paths File

Use --paths to provide a file containing paths:
tree-sitter highlight --paths file-list.txt

Standard Input

If no paths are provided, input is read from stdin:
echo "const x = 42;" | tree-sitter highlight --scope source.js

Output Formats

Terminal (ANSI)

By default, outputs colored text to the terminal:
tree-sitter highlight example.js

HTML

Generate an HTML document with syntax highlighting:
tree-sitter highlight --html example.js > output.html

HTML with CSS Classes

Generate HTML with CSS classes instead of inline styles:
tree-sitter highlight --html --css-classes example.js > output.html

Options

Output Options

-H, --html
flag
Output an HTML document with syntax highlighting.
--css-classes
flag
Output HTML with CSS classes instead of inline styles. Must be used with --html.
-q, --quiet
flag
Suppress main output.
-t, --time
flag
Print the time taken to highlight the file.

Validation Options

--check
flag
Check that the highlighting captures conform strictly to the standards.
--captures-path
path
The path to a file with captures. These captures are considered the “standard” captures to compare against when using --check.

Query Options

--query-paths
paths
The paths to query files to use for syntax highlighting. These should end in highlights.scm. Can be specified multiple times.

Input Options

--paths
file
The path to a file that contains paths to source files to highlight.
-p, --grammar-path
path
The path to the directory containing the grammar. Implies --rebuild.
--scope
scope
The language scope to use for syntax highlighting. Useful when the language is ambiguous.
--encoding
encoding
The encoding of the input files. One of utf8, utf16-le, utf16-be.
-n, --test-number
number
Highlight the contents of a specific test.

Build Options

-r, --rebuild
flag
Force a rebuild of the parser before highlighting.
--config-path
path
The path to an alternative configuration (config.json) file. See init-config.

Examples

Highlight to Terminal

tree-sitter highlight example.js

Generate HTML

tree-sitter highlight --html example.js > output.html

Generate HTML with CSS Classes

tree-sitter highlight --html --css-classes example.js > output.html

Highlight Multiple Files

tree-sitter highlight src/**/*.js

Highlight with Custom Query

tree-sitter highlight --query-paths custom-highlights.scm example.js

Check Highlight Conformance

tree-sitter highlight --check --captures-path standard-captures.txt example.js

Highlight with Performance Measurement

tree-sitter highlight --time example.js

Theme Configuration

Colors are controlled by the theme in your config file. See init-config for information on configuring the theme.