Pearly Soames wanted gold and silver, but not, in the way of common thieves, for wealth. He wanted them because they shone and were pure. Strange, afflicted, and deformed, he sought a cure in the abstract relation of colors.
– Mark Helprin, Winter’s Tale
Pearly is an Elixir library for syntax highlighting using Sublime Text syntax definitions.
I needed to highlight code for use in HTML pages. I considered using Makeup, but I needed to support more languages than it currently does. Another option would have been using Pygments via Highlight, but I wanted to avoid depending on Python.
Instead I wrote Pearly, a small library and Rustler NIF for the Syntect library. Syntect is a really nice Rust library for syntax highlighting using Sublime Text syntax definitions, and it supports a lot of languages out of the box.
It is not currently possible to provide additional syntaxes or themes beyond those that are built in, but I plan to add support for this when I get a chance.
This is very cool. This was supposed to be my approach with Makeup (only in pure Elixir), but parsing and compiling SublimeText grammars is very hard and a little confusing (they do funny things with regexs).
It would be awesome if Makeup used SublimeText grammars, but I would not have taken on this project had I needed to parse them and I can understand why you didn’t want to climb that particular mountain.
On one hand, it would be pretty cool, because it would give us lots of languages for free. On the other hand, Makeup supports things that SublimeText grammars don’t, like matching delimiters, and corrects some problems in the highlighting of function names that are common to many lexers.
Can always make a ‘SublimeTextGrammer’ language for Makeup that can read those regex’s, once they are figured out in full. That would be a nice fall-back for languages not defined via other packages until they are made.
Yes, I can, but it would require writing an interpreter or compiler for Sublime grammars, and that’s hard. I don’t want to use this rust library as a fallback because I don’t want to depend on Rust. I want Makeup to be pure Elixir (otherwise I’d use Pygments as a fallback - I’d rather depend on Python than Rust).