├── .gitignore ├── .editorconfig ├── en.md └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .DS_Store 3 | fork 4 | source -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = false 9 | insert_final_newline = false 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /en.md: -------------------------------------------------------------------------------- 1 | # Chroma - A general purpose syntax highlighter in pure Go [![](https://godoc.org/github.com/alecthomas/chroma?status.svg)](http://godoc.org/github.com/alecthomas/chroma) [![Build Status](https://travis-ci.org/alecthomas/chroma.png)](https://travis-ci.org/alecthomas/chroma) [![Gitter chat](https://badges.gitter.im/alecthomas.png)](https://gitter.im/alecthomas/Lobby) 2 | 3 | > **NOTE:** As Chroma has just been released, its API is still in flux. That said, the high-level interface should not change significantly. 4 | 5 | Chroma takes source code and other structured text and converts it into syntax 6 | highlighted HTML, ANSI-coloured text, etc. 7 | 8 | Chroma is based heavily on [Pygments](http://pygments.org/), and includes 9 | translators for Pygments lexers and styles. 10 | 11 | ## Table of Contents 12 | 13 | 14 | 15 | 1. [Supported languages](#supported-languages) 16 | 1. [Using the library](#using-the-library) 17 | 1. [Quick start](#quick-start) 18 | 1. [Identifying the language](#identifying-the-language) 19 | 1. [Formatting the output](#formatting-the-output) 20 | 1. [The HTML formatter](#the-html-formatter) 21 | 1. [More detail](#more-detail) 22 | 1. [Lexers](#lexers) 23 | 1. [Formatters](#formatters) 24 | 1. [Styles](#styles) 25 | 1. [Command-line interface](#command-line-interface) 26 | 1. [What's missing compared to Pygments?](#whats-missing-compared-to-pygments) 27 | 28 | 29 | 30 | ## Supported languages 31 | 32 | Prefix | Language 33 | :----: | -------- 34 | A | ABNF, ActionScript, ActionScript 3, Ada, Angular2, ANTLR, ApacheConf, APL, AppleScript, Awk 35 | B | Ballerina, Base Makefile, Bash, Batchfile, BlitzBasic, BNF, Brainfuck 36 | C | C, C#, C++, Cassandra CQL, CFEngine3, cfstatement/ColdFusion, CMake, COBOL, CSS, Cap'n Proto, Ceylon, ChaiScript, Cheetah, Clojure, CoffeeScript, Common Lisp, Coq, Crystal, Cython 37 | D | Dart, Diff, Django/Jinja, Docker, DTD 38 | E | EBNF, Elixir, Elm, EmacsLisp, Erlang 39 | F | Factor, Fish, Forth, Fortran, FSharp 40 | G | GAS, GDScript, GLSL, Genshi, Genshi HTML, Genshi Text, Gnuplot, Go, Go HTML Template, Go Text Template, Groovy 41 | H | Handlebars, Haskell, Haxe, Hexdump, HTML, HTTP, Hy 42 | I | Idris, INI, Io 43 | J | Java, JavaScript, JSON, Jsx, Julia, Jungle 44 | K | Kotlin 45 | L | Lighttpd configuration file, LLVM, Lua 46 | M | Mako, Markdown, Mason, Mathematica, MiniZinc, Modula-2, MonkeyC, MorrowindScript, Myghty, MySQL 47 | N | NASM, Newspeak, Nginx configuration file, Nim, Nix 48 | O | Objective-C, OCaml, Octave, OpenSCAD, Org Mode 49 | P | PacmanConf, Perl, PHP, Pig, PkgConfig, Plaintext, PL/pgSQL, PostgreSQL SQL dialect, PostScript, POVRay, PowerShell, Prolog, Protocol Buffer, Puppet, Python, Python 3 50 | Q | QBasic 51 | R | R, Racket, Ragel, reg, reStructuredText, Rexx, Ruby, Rust 52 | S | Sass, Scala, Scheme, Scilab, SCSS, Smalltalk, Smarty, Snobol, Solidity, SPARQL, SQL, SquidConf, Swift, systemd, Systemverilog 53 | T | TASM, Tcl, Tcsh, Termcap, Terminfo, Terraform, TeX, Thrift, TOML, TradingView, Transact-SQL, Turtle, Twig, TypeScript, TypoScript, TypoScriptCssData, TypoScriptHtmlData 54 | V | verilog, VHDL, VimL 55 | W | WDTE 56 | X | XML, Xorg 57 | Y | YAML 58 | 59 | _I will attempt to keep this section up to date, but an authoritative list can be 60 | displayed with `chroma --list`._ 61 | 62 | ## Using the library 63 | 64 | Chroma, like Pygments, has the concepts of 65 | [lexers](https://github.com/alecthomas/chroma/tree/master/lexers), 66 | [formatters](https://github.com/alecthomas/chroma/tree/master/formatters) and 67 | [styles](https://github.com/alecthomas/chroma/tree/master/styles). 68 | 69 | Lexers convert source text into a stream of tokens, styles specify how token 70 | types are mapped to colours, and formatters convert tokens and styles into 71 | formatted output. 72 | 73 | A package exists for each of these, containing a global `Registry` variable 74 | with all of the registered implementations. There are also helper functions 75 | for using the registry in each package, such as looking up lexers by name or 76 | matching filenames, etc. 77 | 78 | In all cases, if a lexer, formatter or style can not be determined, `nil` will 79 | be returned. In this situation you may want to default to the `Fallback` 80 | value in each respective package, which provides sane defaults. 81 | 82 | ### Quick start 83 | 84 | A convenience function exists that can be used to simply format some source 85 | text, without any effort: 86 | 87 | ```go 88 | err := quick.Highlight(os.Stdout, someSourceCode, "go", "html", "monokai") 89 | ``` 90 | 91 | ### Identifying the language 92 | 93 | To highlight code, you'll first have to identify what language the code is 94 | written in. There are three primary ways to do that: 95 | 96 | 1. Detect the language from its filename. 97 | 98 | ```go 99 | lexer := lexers.Match("foo.go") 100 | ``` 101 | 102 | 3. Explicitly specify the language by its Chroma syntax ID (a full list is available from `lexers.Names()`). 103 | 104 | ```go 105 | lexer := lexers.Get("go") 106 | ``` 107 | 108 | 3. Detect the language from its content. 109 | 110 | ```go 111 | lexer := lexers.Analyse("package main\n\nfunc main()\n{\n}\n") 112 | ``` 113 | 114 | In all cases, `nil` will be returned if the language can not be identified. 115 | 116 | ```go 117 | if lexer == nil { 118 | lexer = lexers.Fallback 119 | } 120 | ``` 121 | 122 | At this point, it should be noted that some lexers can be extremely chatty. To 123 | mitigate this, you can use the coalescing lexer to coalesce runs of identical 124 | token types into a single token: 125 | 126 | ```go 127 | lexer = chroma.Coalesce(lexer) 128 | ``` 129 | 130 | ### Formatting the output 131 | 132 | Once a language is identified you will need to pick a formatter and a style (theme). 133 | 134 | ```go 135 | style := styles.Get("swapoff") 136 | if style == nil { 137 | style = styles.Fallback 138 | } 139 | formatter := formatters.Get("html") 140 | if formatter == nil { 141 | formatter = formatters.Fallback 142 | } 143 | ``` 144 | 145 | Then obtain an iterator over the tokens: 146 | 147 | ```go 148 | contents, err := ioutil.ReadAll(r) 149 | iterator, err := lexer.Tokenise(nil, string(contents)) 150 | ``` 151 | 152 | And finally, format the tokens from the iterator: 153 | 154 | ```go 155 | err := formatter.Format(w, style, iterator) 156 | ``` 157 | 158 | ### The HTML formatter 159 | 160 | By default the `html` registered formatter generates standalone HTML with 161 | embedded CSS. More flexibility is available through the `formatters/html` package. 162 | 163 | Firstly, the output generated by the formatter can be customised with the 164 | following constructor options: 165 | 166 | - `Standalone()` - generate standalone HTML with embedded CSS. 167 | - `WithClasses()` - use classes rather than inlined style attributes. 168 | - `ClassPrefix(prefix)` - prefix each generated CSS class. 169 | - `TabWidth(width)` - Set the rendered tab width, in characters. 170 | - `WithLineNumbers()` - Render line numbers (style with `LineNumbers`). 171 | - `HighlightLines(ranges)` - Highlight lines in these ranges (style with `LineHighlight`). 172 | - `LineNumbersInTable()` - Use a table for formatting line numbers and code, rather than spans. 173 | 174 | If `WithClasses()` is used, the corresponding CSS can be obtained from the formatter with: 175 | 176 | ```go 177 | formatter := html.New(html.WithClasses()) 178 | err := formatter.WriteCSS(w, style) 179 | ``` 180 | 181 | ## More detail 182 | 183 | ### Lexers 184 | 185 | See the [Pygments documentation](http://pygments.org/docs/lexerdevelopment/) 186 | for details on implementing lexers. Most concepts apply directly to Chroma, 187 | but see existing lexer implementations for real examples. 188 | 189 | In many cases lexers can be automatically converted directly from Pygments by 190 | using the included Python 3 script `pygments2chroma.py`. I use something like 191 | the following: 192 | 193 | ``` 194 | python3 ~/Projects/chroma/_tools/pygments2chroma.py \ 195 | pygments.lexers.jvm.KotlinLexer \ 196 | > ~/Projects/chroma/lexers/kotlin.go \ 197 | && gofmt -s -w ~/Projects/chroma/lexers/*.go 198 | ``` 199 | 200 | See notes in [pygments-lexers.go](https://github.com/alecthomas/chroma/blob/master/pygments-lexers.txt) 201 | for a list of lexers, and notes on some of the issues importing them. 202 | 203 | ### Formatters 204 | 205 | Chroma supports HTML output, as well as terminal output in 8 colour, 256 colour, and true-colour. 206 | 207 | A `noop` formatter is included that outputs the token text only, and a `tokens` 208 | formatter outputs raw tokens. The latter is useful for debugging lexers. 209 | 210 | ### Styles 211 | 212 | Chroma styles use the [same syntax](http://pygments.org/docs/styles/) as Pygments. 213 | 214 | All Pygments styles have been converted to Chroma using the `_tools/style.py` script. 215 | 216 | For a quick overview of the available styles and how they look, check out the [Chroma Style Gallery](https://xyproto.github.io/splash/docs/). 217 | 218 | ## Command-line interface 219 | 220 | A command-line interface to Chroma is included. It can be installed with: 221 | 222 | ``` 223 | go get -u github.com/alecthomas/chroma/cmd/chroma 224 | ``` 225 | 226 | ## What's missing compared to Pygments? 227 | 228 | - Quite a few lexers, for various reasons (pull-requests welcome): 229 | - Pygments lexers for complex languages often include custom code to 230 | handle certain aspects, such as Perl6's ability to nest code inside 231 | regular expressions. These require time and effort to convert. 232 | - I mostly only converted languages I had heard of, to reduce the porting cost. 233 | - Some more esoteric features of Pygments are omitted for simplicity. 234 | - Though the Chroma API supports content detection, very few languages support them. 235 | I have plans to implement a statistical analyser at some point, but not enough time. 236 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # alecthomas/chroma [![explain]][source] [![translate-svg]][translate-list] 2 | 3 | 4 | 5 | [explain]: http://llever.com/explain.svg 6 | [source]: https://github.com/chinanf-boy/Source-Explain 7 | [translate-svg]: http://llever.com/translate.svg 8 | [translate-list]: https://github.com/chinanf-boy/chinese-translate-list 9 | [size-img]: https://packagephobia.now.sh/badge?p=Name 10 | [size]: https://packagephobia.now.sh/result?p=Name 11 | 12 | 「 纯 Go 中的通用语法高亮显示器 」 13 | 14 | [中文](./readme.md) | [english](https://github.com/alecthomas/chroma) 15 | 16 | --- 17 | 18 | ## 校对 ✅ 19 | 20 | 21 | 22 | 23 | 24 | 翻译的原文 | 与日期 | 最新更新 | 更多 25 | ---|---|---|--- 26 | [commit] | ⏰ 2018-10-21 | ![last] | [中文翻译][translate-list] 27 | 28 | [last]: https://img.shields.io/github/last-commit/alecthomas/chroma.svg 29 | [commit]: https://github.com/alecthomas/chroma/tree/5a473179cfe450c6d80407452c241428de387f6b 30 | 31 | 32 | 33 | - [x] [chroma的使用例子](http://llever.com/2018/11/01/golang-chroma-%E4%BD%BF%E7%94%A8%E4%BE%8B%E5%AD%90/) 34 | 35 | ### 贡献 36 | 37 | 欢迎 👏 勘误/校对/更新贡献 😊 [具体贡献请看](https://github.com/chinanf-boy/chinese-translate-list#贡献) 38 | 39 | ## 生活 40 | 41 | [If help, **buy** me coffee —— 营养跟不上了,给我来瓶营养快线吧! 💰](https://github.com/chinanf-boy/live-need-money) 42 | 43 | --- 44 | 45 | # Chroma - 纯 Go 中的通用语法高亮显示器[![](https://godoc.org/github.com/alecthomas/chroma?status.svg)](http://godoc.org/github.com/alecthomas/chroma) [![Build Status](https://travis-ci.org/alecthomas/chroma.png)](https://travis-ci.org/alecthomas/chroma) [![Gitter chat](https://badges.gitter.im/alecthomas.png)](https://gitter.im/alecthomas/Lobby) 46 | 47 | > **注意:**由于 Chroma 刚刚发布,其 API 仍在不断变化.也就是说,高级接口应该不会发生太大变化. 48 | 49 | Chroma 采用源码和其他结构的文本,将其转换为语法高亮的 HTML,ANSI 色彩文本等. 50 | 51 | Chroma 很大程度上依赖于[Pygments :python](http://pygments.org/),包括 Pygments 的`词法分析器-lexers`和`样式-styles`的转移. 52 | 53 | ## 目录 54 | 55 | 56 | 57 | 58 | 59 | - [支持的语言](#%E6%94%AF%E6%8C%81%E7%9A%84%E8%AF%AD%E8%A8%80) 60 | - [使用库](#%E4%BD%BF%E7%94%A8%E5%BA%93) 61 | - [让我们快速开始](#%E8%AE%A9%E6%88%91%E4%BB%AC%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B) 62 | - [识别语言](#%E8%AF%86%E5%88%AB%E8%AF%AD%E8%A8%80) 63 | - [格式化输出](#%E6%A0%BC%E5%BC%8F%E5%8C%96%E8%BE%93%E5%87%BA) 64 | - [HTML 格式化程序](#html-%E6%A0%BC%E5%BC%8F%E5%8C%96%E7%A8%8B%E5%BA%8F) 65 | - [更多详情](#%E6%9B%B4%E5%A4%9A%E8%AF%A6%E6%83%85) 66 | - [Lexers-词法分析器](#lexers-%E8%AF%8D%E6%B3%95%E5%88%86%E6%9E%90%E5%99%A8) 67 | - [格式化程序](#%E6%A0%BC%E5%BC%8F%E5%8C%96%E7%A8%8B%E5%BA%8F) 68 | - [样式](#%E6%A0%B7%E5%BC%8F) 69 | - [命令行界面](#%E5%91%BD%E4%BB%A4%E8%A1%8C%E7%95%8C%E9%9D%A2) 70 | - [与 Pygments 相比有什么缺失?](#%E4%B8%8E-pygments-%E7%9B%B8%E6%AF%94%E6%9C%89%E4%BB%80%E4%B9%88%E7%BC%BA%E5%A4%B1) 71 | 72 | 73 | 74 | ## 支持的语言 75 | 76 | | 字首 | 语言 | 77 | | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 78 | | A | ABNF, ActionScript, ActionScript 3, Ada, Angular2, ANTLR, ApacheConf, APL, AppleScript, Awk | 79 | | B | Ballerina, Base Makefile, Bash, Batchfile, BlitzBasic, BNF, Brainfuck | 80 | | C | C, C#, C++, Cassandra CQL, CFEngine3, cfstatement/ColdFusion, CMake, COBOL, CSS, Cap'n Proto, Ceylon, ChaiScript, Cheetah, Clojure, CoffeeScript, Common Lisp, Coq, Crystal, Cython | 81 | | D | Dart, Diff, Django/Jinja, Docker, DTD | 82 | | E | EBNF, Elixir, Elm, EmacsLisp, Erlang | 83 | | F | Factor, Fish, Forth, Fortran, FSharp | 84 | | G | GAS, GDScript, GLSL, Genshi, Genshi HTML, Genshi Text, Gnuplot, Go, Go HTML Template, Go Text Template, Groovy | 85 | | H | Handlebars, Haskell, Haxe, Hexdump, HTML, HTTP, Hy | 86 | | I | Idris, INI, Io | 87 | | J | Java, JavaScript, JSON, Jsx, Julia, Jungle | 88 | | K | Kotlin | 89 | | L | Lighttpd configuration file, LLVM, Lua | 90 | | M | Mako, Markdown, Mason, Mathematica, MiniZinc, Modula-2, MonkeyC, MorrowindScript, Myghty, MySQL | 91 | | N | NASM, Newspeak, Nginx configuration file, Nim, Nix | 92 | | O | Objective-C, OCaml, Octave, OpenSCAD, Org Mode | 93 | | P | PacmanConf, Perl, PHP, Pig, PkgConfig, Plaintext, PL/pgSQL, PostgreSQL SQL dialect, PostScript, POVRay, PowerShell, Prolog, Protocol Buffer, Puppet, Python, Python 3 | 94 | | Q | QBasic | 95 | | R | R, Racket, Ragel, reg, reStructuredText, Rexx, Ruby, Rust | 96 | | S | Sass, Scala, Scheme, Scilab, SCSS, Smalltalk, Smarty, Snobol, Solidity, SPARQL, SQL, SquidConf, Swift, systemd, Systemverilog | 97 | | T | TASM, Tcl, Tcsh, Termcap, Terminfo, Terraform, TeX, Thrift, TOML, TradingView, Transact-SQL, Turtle, Twig, TypeScript, TypoScript, TypoScriptCssData, TypoScriptHtmlData | 98 | | V | verilog, VHDL, VimL | 99 | | W | WDTE | 100 | | X | XML, Xorg | 101 | | Y | YAML | 102 | 103 | _我将保持此部分的更新,但更及时与权威的列表在`chroma --list`._ 104 | 105 | ## 使用库 106 | 107 | 与 Pygments 一样,Chroma 具有以下概念[词法分析器-lexers](https://github.com/alecthomas/chroma/tree/master/lexers),[格式化-formatters](https://github.com/alecthomas/chroma/tree/master/formatters)和[款式-styles](https://github.com/alecthomas/chroma/tree/master/styles). 108 | 109 | Lexers 将源文本转换为标记流数据,styles 指定相应的标记类型如何映射到颜色,格式化程序将标记和 styles 转换为格式化输出. 110 | 111 | 每个概念都有一个包,包含一个全局包`Registry`,其中具有所有已注册实现的变量。还有一些辅助函数可以让每个包都能使用注册表,例如按名称查找词法分析器,或匹配文件名等. 112 | 113 | 在所有情况下,如果无法确定词法分析器,格式化程序或样式,`nil`将返回。在这种情况下,您可能希望默认为每个包中的`Fallback`值,此提供合理的默认值. 114 | 115 | ### 让我们快速开始 116 | 117 | 存在一个便利功能,可以用来简单格式一些源文本,而不需要任何努力: 118 | 119 | ```go 120 | err := quick.Highlight(os.Stdout, someSourceCode, "go", "html", "monokai") 121 | ``` 122 | 123 | ### 识别语言 124 | 125 | 要高亮代码,首先必须确定编写代码的语言.有三种主要方法: 126 | 127 | 1. 从文件名中检测语言. 128 | 129 | ```go 130 | lexer := lexers.Match("foo.go") 131 | ``` 132 | 133 | 2. 通过其 Chroma 语法 ID 明确指定语言(可从`lexers.Names()`中获取完整列表). 134 | 135 | ```go 136 | lexer := lexers.Get("go") 137 | ``` 138 | 139 | 3. 从其内容中,分析语言. 140 | 141 | ```go 142 | lexer := lexers.Analyse("package main\n\nfunc main()\n{\n}\n") 143 | ``` 144 | 145 | 在所有情况下,如果语言无法识别,返回一个`nil`. 146 | 147 | ```go 148 | if lexer == nil { 149 | lexer = lexers.Fallback 150 | } 151 | ``` 152 | 153 | 在这一点上,应该指出一些词法分析者可能不尽如人意。为了缓解这种情况,您可以使用合并词法分析器,将相同标记类型的运行合并到一个标记中: 154 | 155 | ```go 156 | lexer = chroma.Coalesce(lexer) 157 | ``` 158 | 159 | ### 格式化输出 160 | 161 | 识别语言后,您需要选择格式化程序和样式(主题). 162 | 163 | ```go 164 | style := styles.Get("swapoff") 165 | if style == nil { 166 | style = styles.Fallback 167 | } 168 | formatter := formatters.Get("html") 169 | if formatter == nil { 170 | formatter = formatters.Fallback 171 | } 172 | ``` 173 | 174 | 然后获取**Token-标记**上的迭代器: 175 | 176 | ```go 177 | contents, err := ioutil.ReadAll(r) 178 | iterator, err := lexer.Tokenise(nil, string(contents)) 179 | ``` 180 | 181 | 最后,从迭代器格式化标记: 182 | 183 | ```go 184 | err := formatter.Format(w, style, iterator) 185 | ``` 186 | 187 | ### HTML 格式化程序 188 | 189 | 默认情况下,已注册的`html`格式化程序会生成带有嵌入式 CSS 的独立 HTML。更多的灵活性可以试试`formatters/html`包. 190 | 191 | 首先,可以使用以下构造函数选项,自定义格式化程序生成的输出: 192 | 193 | - `Standalone()`- 使用嵌入式 CSS 生成独立 HTML. 194 | - `WithClasses()`- 使用类,而不是内联样式属性. 195 | - `ClassPrefix(prefix)`- 为每个生成的 CSS 类添加前缀. 196 | - `TabWidth(width)`- 以字符为单位设置渲染的标签宽度. 197 | - `WithLineNumbers()`- 渲染行号(`LineNumbers`样式). 198 | - `HighlightLines(ranges)`- 突出显示这些范围内的线条(`LineHighlight`样式). 199 | - `LineNumbersInTable()`- 使用table,来格式化行号和代码,而不是 span. 200 | 201 | 如果是使用`WithClasses()`,可以从格式化程序中,获取相应的 CSS: 202 | 203 | ```go 204 | formatter := html.New(html.WithClasses()) 205 | err := formatter.WriteCSS(w, style) 206 | ``` 207 | 208 | ## 更多详情 209 | 210 | ### Lexers-词法分析器 211 | 212 | 见[Pygments 文档](http://pygments.org/docs/lexerdevelopment/)有关实施词法分析器的详细信息.大多数概念直接适用于 Chroma,但请参阅现有的 lexer 实现,以获取实际示例. 213 | 214 | 在许多情况下,可以使用附带的 Python 3 脚本`pygments2chroma.py`直接从 Pygments 那里,自动转换词法分析器。如下: 215 | 216 | ``` 217 | python3 ~/Projects/chroma/_tools/pygments2chroma.py \ 218 | pygments.lexers.jvm.KotlinLexer \ 219 | > ~/Projects/chroma/lexers/kotlin.go \ 220 | && gofmt -s -w ~/Projects/chroma/lexers/*.go 221 | ``` 222 | 223 | 见[pygments-lexers.go](https://github.com/alecthomas/chroma/blob/master/pygments-lexers.txt)的笔记,其记录了有关词法分析器的列表,以及有关导入它们的一些问题的说明. 224 | 225 | ### 格式化程序 226 | 227 | Chroma 支持 HTML 输出,以及 8 色,256 色和真彩色的终端输出. 228 | 229 | 一个`noop`仅包含,输出标记文本的格式化程序,以及 一个`tokens`formatter 输出原始标记。后者对调试词法分析器非常有用. 230 | 231 | ### 样式 232 | 233 | Chroma styles使用与Pygments[相同的语法](http://pygments.org/docs/styles/). 234 | 235 | 所有 Pygments 样式都被`_tools/style.py`脚本转换为 Chroma的了. 236 | 237 | 有关可用样式,及其外观的简易概述,请查看[Chroma 主题画廊](https://xyproto.github.io/splash/docs/). 238 | 239 | ## 命令行界面 240 | 241 | 包括 Chroma 的命令行界面.它可以安装: 242 | 243 | ``` 244 | go get -u github.com/alecthomas/chroma/cmd/chroma 245 | ``` 246 | 247 | ## 与 Pygments 相比有什么缺失? 248 | 249 | - 由于各种原因(欢迎提出请求),其中相当多的lexers: 250 | - Pygments对 复杂语言的词法分析器,通常包含处理某些方面的自定义代码,例如 Perl6 在正则表达式中嵌套代码的能力。这需要时间和精力来转换. 251 | - 我大多只转换我听过的语言,以降低移植成本. 252 | - 为简单起见,省略了 Pygments 的一些太深奥的功能. 253 | - 虽然 Chroma API 支持内容检测,但仅有少有语言支持。我计划在哪个时候实现一个统计分析仪,但时间不够. 254 | --------------------------------------------------------------------------------