A general purpose syntax highlighter in pure Go

Chroma — A general purpose syntax highlighter in pure Go Golang Documentation CircleCI Go Report Card Slack chat

NOTE: As Chroma has just been released, its API is still in flux. That said, the high-level interface should not change significantly.

Chroma takes source code and other structured text and converts it into syntax highlighted HTML, ANSI-coloured text, etc.

Chroma is based heavily on Pygments, and includes translators for Pygments lexers and styles.

Table of Contents

  1. Table of Contents
  2. Supported languages
  3. Try it
  4. Using the library
    1. Quick start
    2. Identifying the language
    3. Formatting the output
    4. The HTML formatter
  5. More detail
    1. Lexers
    2. Formatters
    3. Styles
  6. Command-line interface
  7. What's missing compared to Pygments?

Supported languages

Prefix Language
A ABAP, ABNF, ActionScript, ActionScript 3, Ada, Angular2, ANTLR, ApacheConf, APL, AppleScript, Arduino, Awk
B Ballerina, Base Makefile, Bash, Batchfile, BibTeX, BlitzBasic, BNF, Brainfuck
C C, C#, C++, Caddyfile, Caddyfile Directives, Cap'n Proto, Cassandra CQL, Ceylon, CFEngine3, cfstatement, ChaiScript, Cheetah, Clojure, CMake, COBOL, CoffeeScript, Common Lisp, Coq, Crystal, CSS, Cython
D D, Dart, Diff, Django/Jinja, Docker, DTD
E EBNF, Elixir, Elm, EmacsLisp, Erlang
F Factor, Fish, Forth, Fortran, FSharp
G GAS, GDScript, Genshi, Genshi HTML, Genshi Text, Gherkin, GLSL, Gnuplot, Go, Go HTML Template, Go Text Template, GraphQL, Groovy
H Handlebars, Haskell, Haxe, HCL, Hexdump, HLB, HTML, HTTP, Hy
I Idris, Igor, INI, Io
J J, Java, JavaScript, JSON, Julia, Jungle
K Kotlin
L Lighttpd configuration file, LLVM, Lua
M Mako, markdown, Mason, Mathematica, Matlab, MiniZinc, MLIR, Modula-2, MonkeyC, MorrowindScript, Myghty, MySQL
N NASM, Newspeak, Nginx configuration file, Nim, Nix
O Objective-C, OCaml, Octave, OpenSCAD, Org Mode
P PacmanConf, Perl, PHP, PHTML, Pig, PkgConfig, PL/pgSQL, plaintext, Pony, PostgreSQL SQL dialect, PostScript, POVRay, PowerShell, Prolog, PromQL, Protocol Buffer, Puppet, Python, Python 3
Q QBasic
R R, Racket, Ragel, react, ReasonML, reg, reStructuredText, Rexx, Ruby, Rust
S SAS, Sass, Scala, Scheme, Scilab, SCSS, Smalltalk, Smarty, Snobol, Solidity, SPARQL, SQL, SquidConf, Standard ML, Stylus, Swift, SYSTEMD, systemverilog
T TableGen, TASM, Tcl, Tcsh, Termcap, Terminfo, Terraform, TeX, Thrift, TOML, TradingView, Transact-SQL, Turing, Turtle, Twig, TypeScript, TypoScript, TypoScriptCssData, TypoScriptHtmlData
V VB.net, verilog, VHDL, VimL, vue
W WDTE
X XML, Xorg
Y YAML, YANG
Z Zig

I will attempt to keep this section up to date, but an authoritative list can be displayed with chroma --list.

Try it

Try out various languages and styles on the Chroma Playground.

Using the library

Chroma, like Pygments, has the concepts of lexers, formatters and styles.

Lexers convert source text into a stream of tokens, styles specify how token types are mapped to colours, and formatters convert tokens and styles into formatted output.

A package exists for each of these, containing a global Registry variable with all of the registered implementations. There are also helper functions for using the registry in each package, such as looking up lexers by name or matching filenames, etc.

In all cases, if a lexer, formatter or style can not be determined, nil will be returned. In this situation you may want to default to the Fallback value in each respective package, which provides sane defaults.

Quick start

A convenience function exists that can be used to simply format some source text, without any effort:

err := quick.Highlight(os.Stdout, someSourceCode, "go", "html", "monokai")

Identifying the language

To highlight code, you'll first have to identify what language the code is written in. There are three primary ways to do that:

  1. Detect the language from its filename.

    lexer := lexers.Match("foo.go")
  2. Explicitly specify the language by its Chroma syntax ID (a full list is available from lexers.Names()).

    lexer := lexers.Get("go")
  3. Detect the language from its content.

    lexer := lexers.Analyse("package main\n\nfunc main()\n{\n}\n")

In all cases, nil will be returned if the language can not be identified.

if lexer == nil {
  lexer = lexers.Fallback
}

At this point, it should be noted that some lexers can be extremely chatty. To mitigate this, you can use the coalescing lexer to coalesce runs of identical token types into a single token:

lexer = chroma.Coalesce(lexer)

Formatting the output

Once a language is identified you will need to pick a formatter and a style (theme).

style := styles.Get("swapoff")
if style == nil {
  style = styles.Fallback
}
formatter := formatters.Get("html")
if formatter == nil {
  formatter = formatters.Fallback
}

Then obtain an iterator over the tokens:

contents, err := ioutil.ReadAll(r)
iterator, err := lexer.Tokenise(nil, string(contents))

And finally, format the tokens from the iterator:

err := formatter.Format(w, style, iterator)

The HTML formatter

By default the html registered formatter generates standalone HTML with embedded CSS. More flexibility is available through the formatters/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.
  • TabWidth(width) - Set the rendered tab width, in characters.
  • WithLineNumbers() - Render line numbers (style with LineNumbers).
  • LinkableLineNumbers() - Make the line numbers linkable and be a link to themselves.
  • HighlightLines(ranges) - Highlight lines in these ranges (style with LineHighlight).
  • LineNumbersInTable() - Use a table for formatting line numbers and code, rather than spans.

If WithClasses() is used, the corresponding CSS can be obtained from the formatter with:

formatter := html.New(html.WithClasses())
err := formatter.WriteCSS(w, style)

More detail

Lexers

See the Pygments documentation for details on implementing lexers. Most concepts apply directly to Chroma, but see existing lexer implementations for real examples.

In many cases lexers can be automatically converted directly from Pygments by using the included Python 3 script pygments2chroma.py. I use something like the following:

python3 ~/Projects/chroma/_tools/pygments2chroma.py \
  pygments.lexers.jvm.KotlinLexer \
  > ~/Projects/chroma/lexers/kotlin.go \
  && gofmt -s -w ~/Projects/chroma/lexers/*.go

See notes in pygments-lexers.go for a list of lexers, and notes on some of the issues importing them.

Formatters

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

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

Styles

Chroma styles use the same syntax as Pygments.

All Pygments styles have been converted to Chroma using the _tools/style.py script.

When you work with one of Chroma's styles, know that the chroma.Background token type provides the default style for tokens. It does so by defining a foreground color and background color.

For example, this gives each token name not defined in the style a default color of #f8f8f8 and uses #000000 for the highlighted code block's background:

chroma.Background: "#f8f8f2 bg:#000000",

Also, token types in a style file are hierarchical. For instance, when CommentSpecial is not defined, Chroma uses the token style from Comment. So when several comment tokens use the same color, you'll only need to define Comment and override the one that has a different color.

For a quick overview of the available styles and how they look, check out the Chroma Style Gallery.

Command-line interface

A command-line interface to Chroma is included. It can be installed with:

go get -u github.com/alecthomas/chroma/cmd/chroma

What's missing compared to Pygments?

  • Quite a few lexers, for various reasons (pull-requests welcome):
    • Pygments lexers for complex languages often include custom code to handle certain aspects, such as Perl6's ability to nest code inside regular expressions. These require time and effort to convert.
    • I mostly only converted languages I had heard of, to reduce the porting cost.
  • Some more esoteric features of Pygments are omitted for simplicity.
  • Though the Chroma API supports content detection, very few languages support them. I have plans to implement a statistical analyser at some point, but not enough time.
Comments
  • Reduce init costs

    Reduce init costs

    What problem does this feature solve?

    While testing the new init cost debugging output in go 1.16, I found that chroma dominates the init costs in Hugo's dependencies.

    $ go version
    go version go1.16beta1 linux/amd64
    $ GODEBUG=inittrace=1 ./hugo version 2>&1 | rg chroma | tee time.txt
    init github.com/alecthomas/chroma @4.3 ms, 0.056 ms clock, 14208 bytes, 13 allocs
    init github.com/alecthomas/chroma/lexers/internal @4.4 ms, 0.003 ms clock, 1368 bytes, 14 allocs
    init github.com/alecthomas/chroma/lexers/a @4.4 ms, 0.22 ms clock, 98208 bytes, 1297 allocs
    init github.com/alecthomas/chroma/lexers/b @4.7 ms, 0.21 ms clock, 78344 bytes, 1140 allocs
    init github.com/alecthomas/chroma/lexers/p @4.9 ms, 0.57 ms clock, 172048 bytes, 1792 allocs
    init github.com/alecthomas/chroma/lexers/c @5.5 ms, 0.85 ms clock, 427400 bytes, 3415 allocs
    init github.com/alecthomas/chroma/lexers/j @6.4 ms, 0.12 ms clock, 60728 bytes, 940 allocs
    init github.com/alecthomas/chroma/lexers/h @6.5 ms, 0.34 ms clock, 177168 bytes, 2622 allocs
    init github.com/alecthomas/chroma/lexers/circular @6.9 ms, 0.049 ms clock, 21384 bytes, 401 allocs
    init github.com/alecthomas/chroma/lexers/d @7.0 ms, 0.055 ms clock, 33240 bytes, 570 allocs
    init github.com/alecthomas/chroma/lexers/e @7.0 ms, 0.41 ms clock, 198736 bytes, 954 allocs
    init github.com/alecthomas/chroma/lexers/f @7.5 ms, 0.17 ms clock, 66424 bytes, 884 allocs
    init github.com/alecthomas/chroma/lexers/g @7.7 ms, 0.21 ms clock, 110464 bytes, 1265 allocs
    init github.com/alecthomas/chroma/lexers/i @7.9 ms, 0.14 ms clock, 83176 bytes, 244 allocs
    init github.com/alecthomas/chroma/lexers/k @8.1 ms, 0.084 ms clock, 144168 bytes, 195 allocs
    init github.com/alecthomas/chroma/lexers/l @8.2 ms, 0.054 ms clock, 19976 bytes, 177 allocs
    init github.com/alecthomas/chroma/lexers/m @8.3 ms, 0.14 ms clock, 88800 bytes, 971 allocs
    init github.com/alecthomas/chroma/lexers/n @8.4 ms, 0.081 ms clock, 47064 bytes, 657 allocs
    init github.com/alecthomas/chroma/lexers/o @8.5 ms, 0.14 ms clock, 74344 bytes, 701 allocs
    init github.com/alecthomas/chroma/lexers/q @8.7 ms, 0.011 ms clock, 6632 bytes, 86 allocs
    init github.com/alecthomas/chroma/lexers/r @8.7 ms, 0.45 ms clock, 227896 bytes, 2621 allocs
    init github.com/alecthomas/chroma/lexers/s @9.2 ms, 1.0 ms clock, 497760 bytes, 2990 allocs
    init github.com/alecthomas/chroma/lexers/t @10 ms, 0.94 ms clock, 133456 bytes, 1756 allocs
    init github.com/alecthomas/chroma/lexers/v @11 ms, 0.15 ms clock, 45904 bytes, 655 allocs
    init github.com/alecthomas/chroma/lexers/w @11 ms, 0.003 ms clock, 2344 bytes, 25 allocs
    init github.com/alecthomas/chroma/lexers/x @11 ms, 0.017 ms clock, 5496 bytes, 94 allocs
    init github.com/alecthomas/chroma/lexers/y @11 ms, 0.039 ms clock, 12312 bytes, 141 allocs
    init github.com/alecthomas/chroma/lexers/z @11 ms, 0.015 ms clock, 6576 bytes, 70 allocs
    init github.com/alecthomas/chroma/lexers @11 ms, 0.040 ms clock, 11344 bytes, 204 allocs
    init github.com/alecthomas/chroma/styles @11 ms, 1.6 ms clock, 330664 bytes, 1962 allocs
    $ cat time.txt | awk '$5 > 0 {print $5}' | paste -sd+ | bc
    8.477
    $ cat time.txt | awk '$5 > 0 {print $8}' | paste -sd+ | bc
    3193424
    $ cat time.txt | awk '$5 > 0 {print $10}' | paste -sd+ | bc
    28847
    

    The last 3 commands are summing different columns: 8.477 ms clock, 3193424 bytes, and 28847 allocs.

    What feature do you propose?

    Refactor chroma's lexers to reduce init costs.

    Looking at the lexers packages, I suspect most of problem is the Rules definitions. I would propose deferring the Rules definition until it's needed (similar to how regexp compilation is deferred). Instead of building the Rules on init, pass a function to NewLexer that can return the rules once needed.

  • PHP is not recognized without leading, opening PHP tag

    PHP is not recognized without leading, opening PHP tag

    While using Chroma in the Hugo static site generator, I found that PHP code is not recognized by Chroma, without an opening PHP tag.

    This has already been mentioned in #80 but that issue was closed.

    As of now, this though still seems to be an issue/problem, as I found out here, where my code wasn't correctly recognized/highlighted without that leading PHP tag.

    How can I help to get this fixed for future versions?

  • Can C# highlight also include classes, interfaces, enums?

    Can C# highlight also include classes, interfaces, enums?

    Chroma is great and I'm happy with it. But I think the C# lexer can improved. Currently, it doesn't recognise standard .NET framework classes, interfaces, and enumerations. I think the Chroma highlight will be for the better if we include those.

    As an example, here's how a small code snippet looks like in Visual Studio:

    code-highlight-visua-studio

    With Chroma's C# lexer highlighting, I see this:

    code-highlight-chroma

    It's pretty colourless in Chroma, honestly, and I think the lightblue highlighting of DriveInfo, IEnumerable, Directory, and Console here would really add value in making the code easier to read and interpret.

    Is there a way to expand the C# lexer for this? Perhaps Alec has an idea, or perhaps otherwise you @steambap? (I ping you because you made the original lexer, and have a better understanding of how it works than I do.)

  • Playground v2.0.0-alpha2 is broken

    Playground v2.0.0-alpha2 is broken

    Playground (https://swapoff.org/chroma/playground/) looks broken. It was OK yesterday.

    Environment: Firefox 96.0 on Xubuntu 21.10.

    Current output (I tried different languages) :

    Screenshot_2022-02-22_14-23-48

  • Support Fennel.

    Support Fennel.

    This adds support for the Fennel programming language: https://fennel-lang.org

    I couldn't find much explanation for what the different lexer rules meant, so I based it off of Clojure's lexer since the two languages share a very similar syntax.

    I also included a program to generate a list of keywords from Fennel's own listing, which will make it easier to update in the future.

  • Add `InlineCode` option for inline code blocks

    Add `InlineCode` option for inline code blocks

    • Add an InlineCode option for inline code blocks, which wraps the code in code tag and doesn't wrap the code by Line and CodeLine
    • When PreventSurroundingPre option is enabled, do not wrap the code by Line and CodeLine
    • Write and update related tests
    • Fixes #617

    Please test and review if this behavior is desired and correct.

    Specially PreventSurroundingPre, is everyone OK with this behavior?

  • Image formatter

    Image formatter

    I'd love to use Chroma for generating screenshots of the code – from short carbon.sh-like ones to the long whole files screenshots. Turns out, making long code screenshot it's not a trivial task and most tools solve it by scrolling window and stitching it together. I believe chroma's concept of Formatters is perfect for implementing this functionality natively.

    I might be willing to work on this in my spare time, but I want to check that I'm not duplicating work and not missing something crucial (perhaps it's in progress already, or there some limitations I'm not aware of).

    Thanks in advance for thoughts on this.

  • including chroma brings a lot of dependencies

    including chroma brings a lot of dependencies

    Consider the simplest program including chroma package:

    package main
    
    import (
    	"fmt"
    	_ "github.com/alecthomas/chroma"
    )
    
    func main() {
    	fmt.Printf("Hello\n")
    }
    

    with go.mod:

    module tst
    
    go 1.12
    
    require github.com/alecthomas/chroma v0.6.5
    

    When you go build it, go.sum ends up being:

    github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
    github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
    github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
    github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI=
    github.com/alecthomas/chroma v0.6.5 h1:1gZ11dfxovHkbAM+xzyxjgxhG3Gr7U/cfOXI2eoEBkU=
    github.com/alecthomas/chroma v0.6.5/go.mod h1:fmawHw4BldtHEYrwSxw+YmP0eiiT7JdI1JXEVxmW+nE=
    github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0=
    github.com/alecthomas/kong v0.1.13/go.mod h1:0m2VYms8rH0qbCqVB2gvGHk74bqLIq0HXjCs5bNbNQU=
    github.com/alecthomas/kong v0.1.15/go.mod h1:0m2VYms8rH0qbCqVB2gvGHk74bqLIq0HXjCs5bNbNQU=
    github.com/alecthomas/kong-hcl v0.1.7/go.mod h1:+diJg0tzfMUY/5uDo0dlb7uThhVpWr59PuYkdtRJbms=
    github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=
    github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
    github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk=
    github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
    github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
    github.com/dlclark/regexp2 v1.1.6 h1:CqB4MjHw0MFCDj+PHHjiESmHX+N7t0tJzKvC6M97BRg=
    github.com/dlclark/regexp2 v1.1.6/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
    github.com/gorilla/csrf v1.6.0/go.mod h1:7tSf8kmjNYr7IWDCYhd3U8Ck34iQ/Yw5CJu7bAkHEGI=
    github.com/gorilla/handlers v1.4.1/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
    github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
    github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
    github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
    github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
    github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
    github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
    github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
    github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
    github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
    github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
    github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
    github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
    github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
    github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
    github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
    golang.org/x/sys v0.0.0-20181128092732-4ed8d59d0b35/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
    

    Most of those are dependencies for code under cmd. As a user of the library, I would rather not pull all those dependencies into my project. It's a real cost (in time and bandwidth) when building things with empty module cache (e.g. on a CI server or after running go clean -modcache). Moving code under cmd to a separate repo (e.g. chroma-tools) would fix it.

    I'm not sure if there is a solution that preserves co-location of cmd code in the same repo as chrome code.

  • go: Fix line comment at end of input

    go: Fix line comment at end of input

    Chroma's go lexer did not correctly recognise single line comments if they were at the end of the input without a trailing newline. This PR corrects that issue.

    While having input that ends without a final newline is not normally the case with source code files, it often occurs when using chroma as a library to highlight code snippets displayed in other tools. In particular, this is the case with Hugo. Adding a newline is not a valid workaround, as that can cause dead space to appear below the code snippet.

    Given the following input:

    var x = 1 // Comment 1
    var y = 2 // Comment 2<no-new-line>
    

    ...output before the PR was: screenshot from 2018-02-10 22-54-56

    ...and output after the PR is: screenshot from 2018-02-10 22-54-31

  • Unexpected err class added to Makefile code snippet

    Unexpected err class added to Makefile code snippet

    Please notice the second Makefile code block here:

    image

    I don't know why the second block has err class added to all the identifiers.

    Here is the Markdown for the same:

    -   **`infodir`:** Org Info installation directory. I like to keep the
        Info file for development version of Org in a separate
        directory.
    
        ```makefile
        infodir = $(prefix)/org/info # Default: $(prefix)/info
        ```
    -   **`ORG_MAKE_DOC`:** Types of Org documentation you'd like to build by
        default.  Below enables generation of the Info and
        PDF Org manuals and the Org reference cards (in
        PDF too).
    
        ```makefile
        # Define below you only need info documentation, the default includes html and pdf
        ORG_MAKE_DOC = info pdf card # html
        ```
    

    Here is the HTML:

    <li><p><strong><code>infodir</code>:</strong> Org Info installation directory. I like to keep the
    Info file for development version of Org in a separate
    directory.</p>
    <div class="highlight"><pre class="chroma"><code class="language-makefile" data-lang="makefile"><span class="nf">infodir = $(prefix)/org/info # Default</span><span class="o">:</span><span class=""> </span><span class="k">$(</span><span class="n">prefix</span><span class="k">)</span><span class="">/</span><span class="n">info</span></code></pre>
    </div></li>
    
    <li><p><strong><code>ORG_MAKE_DOC</code>:</strong> Types of Org documentation you&rsquo;d like to build by
    default.  Below enables generation of the Info and
    PDF Org manuals and the Org reference cards (in
    PDF too).</p>
    <div class="highlight"><pre class="chroma"><code class="language-makefile" data-lang="makefile"><span class="c"># Define below you only need info documentation, the default includes html and pdf
    </span><span class="c"></span><span class="err">ORG_MAKE_DOC</span><span class=""> </span><span class="err">=</span><span class=""> </span><span class="err">info</span><span class=""> </span><span class="err">pdf</span><span class=""> </span><span class="err">card</span><span class=""> </span><span class="err">#</span><span class=""> </span><span class="err">html</span></code></pre>
    </div></li>
    

    This is using this commit of chroma: https://github.com/alecthomas/chroma/commit/c99eebc024740b198c28e1013a22a8292d48dc1a

  • Makefile regexp crash

    Makefile regexp crash

    Describe the bug

    Crashed with a bad regexp when parsing a Makefile. This must be relatively recent as I just updated everything and this occurred -- wasn't a problem before. It seems like a straightforward issue with a bad regexp that shouldn't depend on anything specific in my use-case -- let me know if further details might be relevant and I can provide them.

    panic: failed to compile rule basic.8: error parsing regexp: malformed \k<...> named back reference in `\G(?m)(?:<<-?\s*(\'?)\\?(\w+)[\w\W]+?\2)`
    
    goroutine 11 [running]:
    github.com/alecthomas/chroma.Using.func1(0xc0160410c0, 0x1, 0x1, 0x5196b20, 0xc00039f590, 0x1)
            /Users/oreilly/go/src/github.com/alecthomas/chroma/regexp.go:123 +0xd4
    github.com/alecthomas/chroma.EmitterFunc.Emit(0xc0003ee5e0, 0xc0160410c0, 0x1, 0x1, 0x5196b20, 0xc00039f590, 0x10)
            /Users/oreilly/go/src/github.com/alecthomas/chroma/regexp.go:32 +0x58
    github.com/alecthomas/chroma.(*LexerState).Iterator(0xc000713040, 0x2, 0xc0092be000, 0x389)
            /Users/oreilly/go/src/github.com/alecthomas/chroma/regexp.go:326 +0x622
    github.com/alecthomas/chroma.(*coalescer).Tokenise.func1(0x4011038, 0x20, 0x4e2f660)
            /Users/oreilly/go/src/github.com/alecthomas/chroma/coalesce.go:15 +0x5a
    github.com/alecthomas/chroma.Iterator.Tokens(0xc000a94060, 0x0, 0xc008d64c00, 0xbb4)
            /Users/oreilly/go/src/github.com/alecthomas/chroma/iterator.go:15 +0x3c
    
  • lexers.Get is very slow when the lexer is not found

    lexers.Get is very slow when the lexer is not found

    See benchmark in https://github.com/alecthomas/chroma/pull/713

    I'm not sure if this is cacheable, but you should at least consider a note in the GoDoc, as this came as a pretty big surprise to me when I found this lighting up like a Christmas tree in a pprof profile.

  • lexers: Add benchmark for lexers.Get

    lexers: Add benchmark for lexers.Get

    BenchmarkLexersGet/Known-10             112448803            10.57 ns/op           0 B/op           0 allocs/op
    BenchmarkLexersGet/Unknown-10                286       4160740 ns/op           0 B/op           0 allocs/op
    
  • Support highlighting cadence

    Support highlighting cadence

    What problem does this feature solve?

    Allows highlighting cadence code

    What feature do you propose?

    See this link for existing solutions for other technology https://github.com/onflow/cadence/blob/master/docs/syntax-highlighting.md

  • WebVTT syntax highlighting

    WebVTT syntax highlighting

    What problem does this feature solve?

    Having WebVTT syntax highlighting in Hugo

    What feature do you propose?

    WebVTT syntax highlighting

    Here is a textmate syntax which might be useful: https://github.com/pepri/subtitles-editor/blob/master/syntaxes/subtitles.tmLanguage.json

Go package for syntax highlighting of code

syntaxhighlight Package syntaxhighlight provides syntax highlighting for code. It currently uses a language-independent lexer and performs decently on

Nov 18, 2022
Search for Go code using syntax trees

gogrep GO111MODULE=on go get mvdan.cc/gogrep Search for Go code using syntax trees. Work in progress. gogrep -x 'if $x != nil { return $x, $*_ }' In

Dec 9, 2022
Toy scripting language with a syntax similar to Rust.

Dust - toy scripting language Toy scripting language with a syntax similar to Rust. ?? Syntax similar to Rust ?? Loose JSON parsing ?? Calling host fu

Sep 28, 2022
A NMEA parser library in pure Go

go-nmea This is a NMEA library for the Go programming language (Golang). Features Parse individual NMEA 0183 sentences Support for sentences with NMEA

Dec 20, 2022
A full-featured regex engine in pure Go based on the .NET engine

regexp2 - full featured regular expressions for Go Regexp2 is a feature-rich RegExp engine for Go. It doesn't have constant time guarantees like the b

Jan 9, 2023
HTML, CSS and SVG static renderer in pure Go

Web render This module implements a static renderer for the HTML, CSS and SVG formats. It consists for the main part of a Golang port of the awesome W

Apr 19, 2022
General purpose library for reading, writing and working with OpenStreetMap data

osm This package is a general purpose library for reading, writing and working with OpenStreetMap data in Go (golang). It has the ability to read OSM

Dec 30, 2022
General purpose library for reading, writing and working with OpenStreetMap data

osm This package is a general purpose library for reading, writing and working with OpenStreetMap data in Go (golang). It has the ability to read OSM

Dec 30, 2022
A general purpose application and library for aligning text.

align A general purpose application that aligns text The focus of this application is to provide a fast, efficient, and useful tool for aligning text.

Sep 27, 2022
Golem is a general purpose, interpreted scripting language.
Golem is a general purpose, interpreted scripting language.

The Golem Programming Language Golem is a general purpose, interpreted scripting language, that brings together ideas from many other languages, inclu

Sep 28, 2022
GhostDB is a distributed, in-memory, general purpose key-value data store that delivers microsecond performance at any scale.
GhostDB is a distributed, in-memory, general purpose key-value data store that delivers microsecond performance at any scale.

GhostDB is designed to speed up dynamic database or API driven websites by storing data in RAM in order to reduce the number of times an external data source such as a database or API must be read. GhostDB provides a very large hash table that is distributed across multiple machines and stores large numbers of key-value pairs within the hash table.

Jan 6, 2023
A general-purpose bot library inspired by Hubot but written in Go. :robot:

Joe Bot ?? A general-purpose bot library inspired by Hubot but written in Go. Joe is a library used to write chat bots in the Go programming language.

Dec 24, 2022
General purpose reloader for all projects.

leaf General purpose reloader for all projects. Command leaf watches for changes in the working directory and runs the specified set of commands whene

Nov 8, 2022
A general purpose cloud provider for Kube-Vip

kube-vip-cloud-provider The Kube-Vip cloud provider is a general purpose cloud-provider for on-prem bare-metal or virtualised environments. It's desig

Jan 8, 2023
A general purpose golang CLI template for Github and Gitlab

golang-cli-template A general purpose project template for golang CLI applications This template serves as a starting point for golang commandline app

Dec 2, 2022
ipx provides general purpose extensions to golang's IP functions in net package

ipx ipx is a library which provides a set of extensions on go's standart IP functions in net package. compability with net package ipx is fully compat

May 24, 2021
A general-purpose Cadence contract for trading NFTs on Flow

NFT Storefront The NFT storefront is a general-purpose Cadence contract for trading NFTs on Flow. NFTStorefront uses modern Cadence run-time type faci

Dec 24, 2022
General-purpose actions for test and release in Go

go-actions This repository provides general-purpose actions for Go. setup This action runs actions/setup-go with actions/cache. For example, jobs: l

Nov 28, 2021
A general purpose project template for golang CLI applications

golang-cli-template A general purpose project template for golang CLI applications golang-cli-template Features Project Layout How to use this templat

Jan 15, 2022
Gpl - University Project on developing a General Purpose Language

General Purpose Language About The Project University Project on developing a Ge

Nov 29, 2022