Skip to content

Commit f4788c0

Browse files
committed
docs: add import to README
1 parent 39115eb commit f4788c0

File tree

1 file changed

+38
-63
lines changed

1 file changed

+38
-63
lines changed

README.md

Lines changed: 38 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,75 +8,72 @@ highlighted HTML, ANSI-coloured text, etc.
88
Chroma is based heavily on [Pygments](http://pygments.org/), and includes
99
translators for Pygments lexers and styles.
1010

11-
<a id="markdown-table-of-contents" name="table-of-contents"></a>
12-
1311
## Table of Contents
1412

1513
<!-- TOC -->
1614

17-
1. [Table of Contents](#table-of-contents)
18-
2. [Supported languages](#supported-languages)
19-
3. [Try it](#try-it)
20-
4. [Using the library](#using-the-library)
15+
1. [Supported languages](#supported-languages)
16+
2. [Try it](#try-it)
17+
3. [Using the library](#using-the-library)
2118
1. [Quick start](#quick-start)
2219
2. [Identifying the language](#identifying-the-language)
2320
3. [Formatting the output](#formatting-the-output)
2421
4. [The HTML formatter](#the-html-formatter)
25-
5. [More detail](#more-detail)
22+
4. [More detail](#more-detail)
2623
1. [Lexers](#lexers)
2724
2. [Formatters](#formatters)
2825
3. [Styles](#styles)
29-
6. [Command-line interface](#command-line-interface)
30-
7. [Testing lexers](#testing-lexers)
31-
8. [What's missing compared to Pygments?](#whats-missing-compared-to-pygments)
26+
5. [Command-line interface](#command-line-interface)
27+
6. [Testing lexers](#testing-lexers)
28+
7. [What's missing compared to Pygments?](#whats-missing-compared-to-pygments)
3229

3330
<!-- /TOC -->
3431

35-
<a id="markdown-supported-languages" name="supported-languages"></a>
36-
3732
## Supported languages
3833

39-
| Prefix | Language |
40-
| :----: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
41-
| A | ABAP, ABNF, ActionScript, ActionScript 3, Ada, Agda, AL, Alloy, Angular2, ANTLR, ApacheConf, APL, AppleScript, ArangoDB AQL, Arduino, ArmAsm, AutoHotkey, AutoIt, Awk |
42-
| B | Ballerina, Bash, Bash Session, Batchfile, BibTeX, Bicep, BlitzBasic, BNF, BQN, Brainfuck |
43-
| C | C, C#, C++, Caddyfile, Caddyfile Directives, Cap'n Proto, Cassandra CQL, Ceylon, CFEngine3, cfstatement, ChaiScript, Chapel, Cheetah, Clojure, CMake, COBOL, CoffeeScript, Common Lisp, Coq, Crystal, CSS, Cython |
44-
| D | D, Dart, Dax, Desktop Entry, Diff, Django/Jinja, dns, Docker, DTD, Dylan |
45-
| E | EBNF, Elixir, Elm, EmacsLisp, Erlang |
46-
| F | Factor, Fennel, Fish, Forth, Fortran, FortranFixed, FSharp |
47-
| G | GAS, GDScript, Genshi, Genshi HTML, Genshi Text, Gherkin, GLSL, Gnuplot, Go, Go HTML Template, Go Text Template, GraphQL, Groff, Groovy |
48-
| H | Handlebars, Hare, Haskell, Haxe, HCL, Hexdump, HLB, HLSL, HolyC, HTML, HTTP, Hy |
49-
| I | Idris, Igor, INI, Io, ISCdhcpd |
50-
| J | J, Java, JavaScript, JSON, Julia, Jungle |
51-
| K | Kotlin |
52-
| L | Lighttpd configuration file, LLVM, Lua |
53-
| M | Makefile, Mako, markdown, Mason, Materialize SQL dialect, Mathematica, Matlab, mcfunction, Meson, Metal, MiniZinc, MLIR, Modula-2, MonkeyC, MorrowindScript, Myghty, MySQL |
54-
| N | NASM, Natural, Newspeak, Nginx configuration file, Nim, Nix |
55-
| O | Objective-C, OCaml, Octave, Odin, OnesEnterprise, OpenEdge ABL, OpenSCAD, Org Mode |
34+
| Prefix | Language |
35+
| :----: | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
36+
| A | ABAP, ABNF, ActionScript, ActionScript 3, Ada, Agda, AL, Alloy, Angular2, ANTLR, ApacheConf, APL, AppleScript, ArangoDB AQL, Arduino, ArmAsm, AutoHotkey, AutoIt, Awk |
37+
| B | Ballerina, Bash, Bash Session, Batchfile, BibTeX, Bicep, BlitzBasic, BNF, BQN, Brainfuck |
38+
| C | C, C#, C++, Caddyfile, Caddyfile Directives, Cap'n Proto, Cassandra CQL, Ceylon, CFEngine3, cfstatement, ChaiScript, Chapel, Cheetah, Clojure, CMake, COBOL, CoffeeScript, Common Lisp, Coq, Crystal, CSS, Cython |
39+
| D | D, Dart, Dax, Desktop Entry, Diff, Django/Jinja, dns, Docker, DTD, Dylan |
40+
| E | EBNF, Elixir, Elm, EmacsLisp, Erlang |
41+
| F | Factor, Fennel, Fish, Forth, Fortran, FortranFixed, FSharp |
42+
| G | GAS, GDScript, Genshi, Genshi HTML, Genshi Text, Gherkin, GLSL, Gnuplot, Go, Go HTML Template, Go Text Template, GraphQL, Groff, Groovy |
43+
| H | Handlebars, Hare, Haskell, Haxe, HCL, Hexdump, HLB, HLSL, HolyC, HTML, HTTP, Hy |
44+
| I | Idris, Igor, INI, Io, ISCdhcpd |
45+
| J | J, Java, JavaScript, JSON, Julia, Jungle |
46+
| K | Kotlin |
47+
| L | Lighttpd configuration file, LLVM, Lua |
48+
| M | Makefile, Mako, markdown, Mason, Materialize SQL dialect, Mathematica, Matlab, mcfunction, Meson, Metal, MiniZinc, MLIR, Modula-2, MonkeyC, MorrowindScript, Myghty, MySQL |
49+
| N | NASM, Natural, Newspeak, Nginx configuration file, Nim, Nix |
50+
| O | Objective-C, OCaml, Octave, Odin, OnesEnterprise, OpenEdge ABL, OpenSCAD, Org Mode |
5651
| P | PacmanConf, Perl, PHP, PHTML, Pig, PkgConfig, PL/pgSQL, plaintext, Plutus Core, Pony, PostgreSQL SQL dialect, PostScript, POVRay, PowerQuery, PowerShell, Prolog, PromQL, Promela, properties, Protocol Buffer, PRQL, PSL, Puppet, Python, Python 2 |
57-
| Q | QBasic, QML |
52+
| Q | QBasic, QML |
5853
| R | R, Racket, Ragel, Raku, react, ReasonML, reg, Rego, reStructuredText, Rexx, RPMSpec, Ruby, Rust |
59-
| S | SAS, Sass, Scala, Scheme, Scilab, SCSS, Sed, Sieve, Smali, Smalltalk, Smarty, Snobol, Solidity, SourcePawn, SPARQL, SQL, SquidConf, Standard ML, stas, Stylus, Svelte, Swift, SYSTEMD, systemverilog |
60-
| T | TableGen, Tal, TASM, Tcl, Tcsh, Termcap, Terminfo, Terraform, TeX, Thrift, TOML, TradingView, Transact-SQL, Turing, Turtle, Twig, TypeScript, TypoScript, TypoScriptCssData, TypoScriptHtmlData |
61-
| V | V, V shell, Vala, VB.net, verilog, VHDL, VHS, VimL, vue |
62-
| W | WDTE, WebGPU Shading Language, Whiley |
63-
| X | XML, Xorg |
64-
| Y | YAML, YANG |
65-
| Z | Z80 Assembly, Zed, Zig |
54+
| S | SAS, Sass, Scala, Scheme, Scilab, SCSS, Sed, Sieve, Smali, Smalltalk, Smarty, Snobol, Solidity, SourcePawn, SPARQL, SQL, SquidConf, Standard ML, stas, Stylus, Svelte, Swift, SYSTEMD, systemverilog |
55+
| T | TableGen, Tal, TASM, Tcl, Tcsh, Termcap, Terminfo, Terraform, TeX, Thrift, TOML, TradingView, Transact-SQL, Turing, Turtle, Twig, TypeScript, TypoScript, TypoScriptCssData, TypoScriptHtmlData |
56+
| V | V, V shell, Vala, VB.net, verilog, VHDL, VHS, VimL, vue |
57+
| W | WDTE, WebGPU Shading Language, Whiley |
58+
| X | XML, Xorg |
59+
| Y | YAML, YANG |
60+
| Z | Z80 Assembly, Zed, Zig |
6661

6762
_I will attempt to keep this section up to date, but an authoritative list can be
6863
displayed with `chroma --list`._
6964

70-
<a id="markdown-try-it" name="try-it"></a>
71-
7265
## Try it
7366

7467
Try out various languages and styles on the [Chroma Playground](https://swapoff.org/chroma/playground/).
7568

76-
<a id="markdown-using-the-library" name="using-the-library"></a>
77-
7869
## Using the library
7970

71+
This is version 2 of Chroma, use the import path:
72+
73+
```go
74+
import "github.com/alecthomas/chroma/v2"
75+
```
76+
8077
Chroma, like Pygments, has the concepts of
8178
[lexers](https://github.com/alecthomas/chroma/tree/master/lexers),
8279
[formatters](https://github.com/alecthomas/chroma/tree/master/formatters) and
@@ -95,8 +92,6 @@ In all cases, if a lexer, formatter or style can not be determined, `nil` will
9592
be returned. In this situation you may want to default to the `Fallback`
9693
value in each respective package, which provides sane defaults.
9794

98-
<a id="markdown-quick-start" name="quick-start"></a>
99-
10095
### Quick start
10196

10297
A convenience function exists that can be used to simply format some source
@@ -106,8 +101,6 @@ text, without any effort:
106101
err := quick.Highlight(os.Stdout, someSourceCode, "go", "html", "monokai")
107102
```
108103

109-
<a id="markdown-identifying-the-language" name="identifying-the-language"></a>
110-
111104
### Identifying the language
112105

113106
To highlight code, you'll first have to identify what language the code is
@@ -147,8 +140,6 @@ token types into a single token:
147140
lexer = chroma.Coalesce(lexer)
148141
```
149142

150-
<a id="markdown-formatting-the-output" name="formatting-the-output"></a>
151-
152143
### Formatting the output
153144

154145
Once a language is identified you will need to pick a formatter and a style (theme).
@@ -177,8 +168,6 @@ And finally, format the tokens from the iterator:
177168
err := formatter.Format(w, style, iterator)
178169
```
179170

180-
<a id="markdown-the-html-formatter" name="the-html-formatter"></a>
181-
182171
### The HTML formatter
183172

184173
By default the `html` registered formatter generates standalone HTML with
@@ -203,12 +192,8 @@ formatter := html.New(html.WithClasses(true))
203192
err := formatter.WriteCSS(w, style)
204193
```
205194

206-
<a id="markdown-more-detail" name="more-detail"></a>
207-
208195
## More detail
209196

210-
<a id="markdown-lexers" name="lexers"></a>
211-
212197
### Lexers
213198

214199
See the [Pygments documentation](http://pygments.org/docs/lexerdevelopment/)
@@ -228,17 +213,13 @@ python3 _tools/pygments2chroma_xml.py \
228213
See notes in [pygments-lexers.txt](https://github.com/alecthomas/chroma/blob/master/pygments-lexers.txt)
229214
for a list of lexers, and notes on some of the issues importing them.
230215

231-
<a id="markdown-formatters" name="formatters"></a>
232-
233216
### Formatters
234217

235218
Chroma supports HTML output, as well as terminal output in 8 colour, 256 colour, and true-colour.
236219

237220
A `noop` formatter is included that outputs the token text only, and a `tokens`
238221
formatter outputs raw tokens. The latter is useful for debugging lexers.
239222

240-
<a id="markdown-styles" name="styles"></a>
241-
242223
### Styles
243224

244225
Chroma styles are defined in XML. The style entries use the
@@ -262,8 +243,6 @@ Also, token types in a style file are hierarchical. For instance, when `CommentS
262243

263244
For a quick overview of the available styles and how they look, check out the [Chroma Style Gallery](https://xyproto.github.io/splash/docs/).
264245

265-
<a id="markdown-command-line-interface" name="command-line-interface"></a>
266-
267246
## Command-line interface
268247

269248
A command-line interface to Chroma is included.
@@ -288,10 +267,6 @@ on under the hood for easy integration with [lesspipe shipping with
288267
Debian and derivatives](https://manpages.debian.org/lesspipe#USER_DEFINED_FILTERS);
289268
for that setup the `chroma` executable can be just symlinked to `~/.lessfilter`.
290269

291-
<a id="markdown-whats-missing-compared-to-pygments" name="whats-missing-compared-to-pygments"></a>
292-
293-
<a id="markdown-testing-lexers" name="testing-lexers"></a>
294-
295270
## Testing lexers
296271

297272
If you edit some lexers and want to try it, open a shell in `cmd/chromad` and run:

0 commit comments

Comments
 (0)