diff --git a/README.md b/README.md index 6ce2dd9..f4aa774 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,32 @@ # Chroma - A general purpose syntax highlighter for Go Chroma takes source code and other structured text and converts it into syntax -highlighted output, as HTML, ANSI-coloured text, etc. +highlighted HTML, ANSI-coloured text, etc. Chroma is based heavily on [Pygments](http://pygments.org/), and includes translaters for Pygments lexers and styles. +## Table of Contents + + + +- [Using the library](#using-the-library) +- [Quick start](#quick-start) + - [Identifying the language](#identifying-the-language) + - [Formatting the output](#formatting-the-output) + - [The HTML formatter](#the-html-formatter) +- [More detail](#more-detail) + - [Lexers](#lexers) + - [Formatters](#formatters) + - [Styles](#styles) +- [Command-line interface](#command-line-interface) +- [What's missing compared to Pygments?](#whats-missing-compared-to-pygments) + + + ## Using the library -Chroma, like Pygments, has the concept of +Chroma, like Pygments, has the concepts of [lexers](https://github.com/alecthomas/chroma/tree/master/lexers), [formatters](https://github.com/alecthomas/chroma/tree/master/formatters) and [styles](https://github.com/alecthomas/chroma/tree/master/styles). @@ -102,6 +120,27 @@ contents, err := ioutil.ReadAll(r) err := lexer.Tokenise(nil, string(contents), writer) ``` +### The HTML formatter + +By default the `html` registered formatter generates standalone HTML with +embedded CSS. More flexibility is available through the `lexers/html` package. + +Firstly, the output generated by the formatter can be customised with the +following constructor options: + +- `Standalone()` - generate standalone HTML with embedded CSS. +- `WithClasses()` - use classes rather than inlined style attributes. +- `ClassPrefix(prefix)` - prefix each generated CSS class. + +If `WithClasses()` is used, the corresponding CSS can be obtained from the formatter with: + +```go +formatter := html.New(html.WithClasses()) +err := formatter.WriteCSS(w, style) +``` + +## More detail + ### Lexers See the [Pygments documentation](http://pygments.org/docs/lexerdevelopment/) diff --git a/cmd/chroma/main.go b/cmd/chroma/main.go index 49200d2..fe5f8d2 100644 --- a/cmd/chroma/main.go +++ b/cmd/chroma/main.go @@ -77,7 +77,7 @@ command, for Go. } if *htmlStylesFlag { formatter := html.New(html.WithClasses()) - formatter.WriteStyles(w, styles.Get(*styleFlag)) + formatter.WriteCSS(w, styles.Get(*styleFlag)) return } formatters.Register("html", html.New(options...)) diff --git a/formatters/html/html.go b/formatters/html/html.go index 336effd..bbb1778 100644 --- a/formatters/html/html.go +++ b/formatters/html/html.go @@ -102,7 +102,7 @@ func (h *HTMLFormatter) formatWithClasses(w io.Writer, style *chroma.Style) (fun fmt.Fprint(w, "\n") } fmt.Fprint(w, "