5 ms·
Chroma – A General purpose syntax highlighter in Go
- ubercow 9y agoI 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 9y ago> 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 9y agoGo has supported shared libraries for a couple years now. I'm sure distro maintainers are taking advantage of this if they think it helpful.
- nerdponx 9y agoGood thing it's Pygments-compatible. There's no sense in completely reinventing the wheel for every programming language.
- aorth 9y agoIt's also really fast: https://mobile.twitter.com/GoHugoIO/status/911582542247153664 https://mobile.twitter.com/GoHugoIO/status/91158254224715366...
- nerdponx 9y agoNice. How much of the improvement is "algorithmic", versus just being written in a more efficient language?
- alecthomas 9y agoI 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.
- trishume 9y agoShameless 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 9y agoI'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 9y ago> 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.
- hnbroseph 9y agorust programs have zero bugs, don't you know. and they practically write themselves in moments.
- sctb 9y agoCould you please stop posting like this and instead comment civilly and substantively? https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html
- archgoon 9y ago> 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!
- deleted 9y ago[deleted]
- conroy 9y agoPerfect 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/a2741b9e6cf45beb3515d81ee1153985 https://gist.github.com/kyleconroy/a2741b9e6cf45beb3515d81ee...
- alecthomas 9y agoNice! 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.