tldr/pages/common/chroma.md

22 lines
836 B
Markdown
Raw Normal View History

2020-10-11 09:44:44 +01:00
# chroma
2023-05-17 16:55:34 +01:00
> A general-purpose syntax highlighter.
> The `--lexer` option is usually unnecessary, as it will be automatically determined based on the file extension.
2020-10-11 09:44:44 +01:00
> More information: <https://github.com/alecthomas/chroma>.
2023-05-17 16:55:34 +01:00
- Highlight source code from a file with the Python lexer and output to `stdout`:
2020-10-11 09:44:44 +01:00
2023-05-17 16:55:34 +01:00
`chroma --lexer {{python}} {{path/to/source_file.py}}`
2020-10-11 09:44:44 +01:00
2023-05-17 16:55:34 +01:00
- Highlight source code from a file with the Go lexer and output to an HTML file:
2020-10-11 09:44:44 +01:00
2023-05-17 16:55:34 +01:00
`chroma --lexer {{go}} --formatter {{html}} {{path/to/source_file.go}} > {{path/to/target_file.html}}`
2020-10-11 09:44:44 +01:00
2023-05-17 16:55:34 +01:00
- Highlight source code from `stdin` with the C++ lexer and output to an SVG file, using the Monokai style:
2020-10-11 09:44:44 +01:00
2023-05-17 16:55:34 +01:00
`{{command}} | chroma --lexer {{c++}} --formatter {{svg}} --style {{monokai}} > {{path/to/target_file.svg}}`
- List available lexers, styles and formatters:
`chroma --list`