
Chroma – A General purpose syntax highlighter in Go - kiyanwang
https://github.com/alecthomas/chroma
======
trishume
Shameless plug for my syntax highlighting library in Rust which uses Sublime
Text 3 grammars, which give much richer highlighting and semantic information
than Pygments:
[https://github.com/trishume/syntect](https://github.com/trishume/syntect)

Sourcegraph also wrote a server using syntect which provides an API for
highlighting, which they use to power their new server, so you can use it from
any language (at a cost): [https://about.sourcegraph.com/blog/announcing-
sourcegraph-2](https://about.sourcegraph.com/blog/announcing-sourcegraph-2)
[https://github.com/sourcegraph/syntect_server](https://github.com/sourcegraph/syntect_server)

~~~
chmike
I'm interested in your package, but as a go programmer. I spend my hollidays
writing a
[colorizer]([https://github.com/chmike/clrz](https://github.com/chmike/clrz))
package in go. I compared many colorizer packages and tried to make something
original. I also wanted to support faster lexers than the one based on regex.
I had to stop by the end of hollidays. Do you have a documentation on how your
lexer works ? Does it use regex only ? I don't understand rust and don't want
to learn it.

~~~
thesmallestcat
> I don't understand rust and don't want to learn it.

Tread lightly, for one more comment about Rust will summon the Rust Evangelism
Strike Force.

~~~
blaenk
The only ones that ever show are the harbingers of the purported evangelism
strike force :)

------
ubercow
I love this so much. So many times I've had to install Python just for
Pygments.

A static binary will be so much easier to maintain.

~~~
josteink
> A static binary will be so much easier to maintain

Repeat that mentality enough times, and I can't wait for the next heart-bleed
to come out.

Distro-maintainers can't exactly be ecstatic about people using Go for more
and more software.

~~~
eikenberry
Go has supported shared libraries for a couple years now. I'm sure distro
maintainers are taking advantage of this if they think it helpful.

------
conroy
Perfect timing, I've been looking to add syntax highlighting to my blog. Took
me about an hour to integrate it this morning. Here's a working example using
the excellent blackfriday package.

[https://gist.github.com/kyleconroy/a2741b9e6cf45beb3515d81ee...](https://gist.github.com/kyleconroy/a2741b9e6cf45beb3515d81ee1153985)

~~~
alecthomas
Nice! I have been meaning to look into integrating Chroma with Blackfriday.
The plugin API looks really nice.

Note that lexers.Analyse() will almost always fail at the moment, as I've only
written support for a couple of languages.

------
archgoon
> and includes translaters for Pygments lexers and styles.

Kudos! So often we see a translation of tool or library to another language,
but no way to leverage existing data / code bases. Nice!

------
nerdponx
Good thing it's Pygments-compatible. There's no sense in completely
reinventing the wheel for every programming language.

~~~
aorth
It's also _really_ fast:

[https://mobile.twitter.com/GoHugoIO/status/91158254224715366...](https://mobile.twitter.com/GoHugoIO/status/911582542247153664)

~~~
nerdponx
Nice. How much of the improvement is "algorithmic", versus just being written
in a more efficient language?

~~~
alecthomas
I would say almost zero is algorithmic, as Chroma very closely adheres to the
design of Pygments.

The improvement is due to two factors, with the first being by far the biggest
factor:

1\. Hugo no longer has to call an external `pygmentize` tool for every
highlight. This removes the overhead of the fork/exec, as well as the (not-
insignificant) overhead of the Python interpreter starting up.

2\. Go is generally a faster language than Python.

The caveat with 2 is that Python can spend large amounts of time in C, eg.
doing regex matching.

