Page
Library
Module
Module type
Parameter
Class
Class type
Source
Command-line interface for the ochre syntax highlighter.
ochre LANG [FILE] [OPTION]...
LANG — Language identifier (e.g. ocaml, javascript, python). Required.FILE — Input file path. Optional when piping/redirection stdin is used.--theme NAME_OR_PATH, -t NAME_OR_PATH — Optional. Built-in theme name (for example dark, light, or tokyonight) or path to a VS Code / TextMate theme JSON file.--theme-dark NAME_OR_PATH — Theme used when terminal mode is detected as dark (same name-or-path resolution as --theme). With --format html, when both --theme-dark and --theme-light are given (and no --theme), produces dual-theme output: the light theme is the default and the dark theme is emitted as CSS custom properties (--ochre-dark-*) for automatic dark-mode switching.--theme-light NAME_OR_PATH — Theme used when terminal mode is detected as light (same name-or-path resolution as --theme). See --theme-dark for dual-theme HTML output.--grammar FILE, -g FILE — Path to a .tmLanguage.json grammar file. Can be specified multiple times. Optional: when omitted, the bundled grammar for LANG is used.--include LANG_OR_PATH, -i LANG_OR_PATH — Additional grammar to load, by bundled name or file path. Use to enable cross-grammar features like HTML embedding CSS/JS. Can be specified multiple times.--format FORMAT, -f FORMAT — Output format: html (default), ansi, latex, svg, or tokens.--html-css-classes — Use CSS class names instead of inline styles for HTML output. Each unique style gets a deterministic class like ochre-<hash>.--line-numbers — Add data-line attributes to line spans in HTML output (1-indexed).--no-default-color — Suppress inline color/background-color on the primary theme; all colors come from CSS custom properties only. Useful with multi-theme output when you control theme switching entirely via CSS.--css-var-prefix PREFIX — CSS custom property prefix for multi-theme output (default: --ochre-).--scopes-data — Add data-scope attributes to token spans in HTML output with TextMate scope names.Using the bundled OCaml grammar and the default theme:
ochre ocaml file.ml
Highlight from stdin with ANSI terminal colors:
cat file.js | ochre javascript --format ansi
ochre ocaml file.ml --theme-light light --theme-dark tokyonight
Bundled grammars can be added by name with --include:
ochre html index.html --include css --include javascript
Custom grammar files are loaded with --grammar:
ochre html index.html \ --grammar ./grammars/html.tmLanguage.json \ --grammar ./grammars/css.tmLanguage.json \ --grammar ./grammars/javascript.tmLanguage.json \ --theme theme.json
or using the short flags:
ochre html index.html -g ./grammars/html.tmLanguage.json -i css -i javascript
ochre bundles the grammars from the tm-grammars package, covering 200+ languages. When no --grammar flag is given, the bundled grammar matching LANG is used; if there is none, the CLI lists the available names.
The language identifiers plaintext, text, and txt need no grammar: they render the input as unstyled tokens with the theme's default colors.
To use a custom grammar, pass --grammar with a path to a .tmLanguage.json file. The language identifier is derived from the filename (e.g. ocaml.tmLanguage.json registers as ocaml). Common sources for grammar files:
~/.vscode/extensions/Themes use the VS Code / TextMate JSON format with colors and tokenColors fields. See VS Code Theme Gallery for available themes.
For the CLI, --theme is optional. ochre uses a built-in theme and auto-picks dark/light from your terminal (using OCHRE_THEME_MODE, TERM_THEME, or COLORFGBG).
You can also pass a built-in name directly, for example --theme dark, instead of a file path.
Built-in themes:
dark — Default dark ochre themelight — Default light ochre themetokyonight — Based on the Tokyonight themeeverforest — Based on the Everforest themeayu — Based on the Ayu dark themecatppuccin — Based on the Catppuccin Mocha themecatppuccin-macchiato — Based on the Catppuccin Macchiato themegruvbox — Based on the Gruvbox dark medium themekanagawa — Based on the Kanagawa Wave themenord — Based on the Nord themematrix — Hacker-style green on black themeone-dark — Based on the Atom One Dark theme