# alecthomas/chroma

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/alecthomas-chroma).**

4,960 stars · 489 forks · Go · NOASSERTION

## Links

- GitHub: https://github.com/alecthomas/chroma
- awesome-repositories: https://awesome-repositories.com/repository/alecthomas-chroma.md

## Topics

`console` `go` `golang` `highlighter` `highlighting` `html` `library` `syntax` `tool`

## Description

Chroma is a syntax highlighter written in Go that converts raw source code into colorized text or HTML. It identifies programming languages and tokens using language-specific lexers to produce highlighted output for various environments.

The project utilizes a theme-driven colorization system that decouples token types from final colors through an intermediate style mapping layer. This allows for custom code theming by mapping specific token categories to foreground and background colors.

The system covers language identification, terminal text formatting for ANSI-compatible viewers, and web code presentation via HTML generation with line numbering and CSS classes. It also includes a command-line interface for colorizing files directly in the terminal.

## Tags

### User Interface & Experience

- [Syntax Highlighting](https://awesome-repositories.com/f/user-interface-experience/presentation-frameworks/code-presentation-utilities/code-line-highlighting/syntax-highlighting.md) — Converts raw source code into colorized text or HTML by analyzing language-specific patterns.
- [Color Themes](https://awesome-repositories.com/f/user-interface-experience/color-themes.md) — Applies visual styles by mapping identified token categories to specific foreground and background colors.
- [Custom Color Theme Definitions](https://awesome-repositories.com/f/user-interface-experience/color-themes/custom-color-theme-definitions.md) — Supports defining new color themes by mapping token types to foreground and background colors. ([source](https://cdn.jsdelivr.net/gh/alecthomas/chroma@master/README.md))
- [Terminal Color Formatting](https://awesome-repositories.com/f/user-interface-experience/component-utilities/color-utilities/terminal-color-formatting.md) — Generates colorized text using ANSI codes for terminals supporting various color palettes. ([source](https://cdn.jsdelivr.net/gh/alecthomas/chroma@master/README.md))
- [Syntax Highlighters](https://awesome-repositories.com/f/user-interface-experience/syntax-highlighters.md) — Functions as a comprehensive syntax highlighter that renders code with color-coded patterns.
- [Terminal Text Coloring](https://awesome-repositories.com/f/user-interface-experience/terminal-text-coloring.md) — Generates ANSI colorized output to improve code readability in terminal environments.
- [Code Block Themes](https://awesome-repositories.com/f/user-interface-experience/visual-theme-configurations/visual-themes/theme-customization/code-block-themes.md) — Allows defining custom color palettes and styles for programming language tokens.
- [Code Presentation Themes](https://awesome-repositories.com/f/user-interface-experience/code-presentation-themes.md) — Creates highlighted HTML snippets with custom styles and line numbers for web display.
- [Syntax Highlighting Styles](https://awesome-repositories.com/f/user-interface-experience/syntax-highlighting-styles.md) — Maps code tokens to visual styles via CSS classes for web browser display. ([source](https://cdn.jsdelivr.net/gh/alecthomas/chroma@master/README.md))

### Programming Languages & Runtimes

- [Programming Language Detectors](https://awesome-repositories.com/f/programming-languages-runtimes/programming-language-detectors.md) — Automatically identifies the programming language of a file or snippet based on content and filename.
- [Programming Language Tokenizers](https://awesome-repositories.com/f/programming-languages-runtimes/programming-language-tokenizers.md) — Analyzes code snippets to break them into meaningful symbols and identifiers for highlighting.
- [Source Code Lexers](https://awesome-repositories.com/f/programming-languages-runtimes/regular-expression-lexer-libraries/source-code-lexers.md) — Uses language-specific lexers to break source code into a stream of typed tokens.

### Development Tools & Productivity

- [CLI Syntax Highlighters](https://awesome-repositories.com/f/development-tools-productivity/cli-syntax-highlighters.md) — Ships a command-line interface for colorizing files directly in the terminal. ([source](https://cdn.jsdelivr.net/gh/alecthomas/chroma@master/README.md))
- [Highlighted HTML Generators](https://awesome-repositories.com/f/development-tools-productivity/html-and-css-code-generators/highlighted-html-generators.md) — Produces highlighted web output with embedded styles, CSS classes, and line numbering.
- [Pluggable Formatters](https://awesome-repositories.com/f/development-tools-productivity/terminal-output-formatters/pluggable-formatters.md) — Provides a pluggable interface to translate token streams into diverse formats like HTML and ANSI.

### Software Engineering & Architecture

- [Style-Definition Decoupling](https://awesome-repositories.com/f/software-engineering-architecture/headless-logic-decoupling/logic-rendering-decouplers/style-definition-decoupling.md) — Implements a decoupling layer that separates internal token types from final color definitions.

### Part of an Awesome List

- [Text Processing](https://awesome-repositories.com/f/awesome-lists/devtools/text-processing.md) — Syntax highlighting library.
