A Crystal reimplementation of the Pygments/Chroma syntax highlighters
Go to file
2024-08-07 15:37:47 -03:00
lexers Initial dumb stuff 2024-08-02 17:03:49 -03:00
scripts Added constants for token abbrev 2024-08-06 20:17:26 -03:00
spec Tweaks 2024-08-06 17:01:14 -03:00
src refactor 2024-08-06 23:34:14 -03:00
styles Basic theme parser 2024-08-06 12:18:03 -03:00
.ameba.yml lint 2024-08-04 20:09:15 -03:00
.editorconfig Initial dumb stuff 2024-08-02 17:03:39 -03:00
.gitignore ignore bench 2024-08-07 15:37:47 -03:00
LICENSE Initial dumb stuff 2024-08-02 17:03:39 -03:00
README.md Updated README 2024-08-06 18:31:29 -03:00
shard.yml Use abbreviated token names in css 2024-08-06 21:28:33 -03:00
TODO.md todo management 2024-08-05 11:14:55 -03:00

TARTRAZINE

Tartrazine is a library to syntax-highlight code. It is a port of Pygments to Crystal. Kind of.

It's not currently usable because it's not finished, but:

  • The lexers work for the implemented languages
  • The provided styles work
  • There is a very very simple HTML formatter

A port of what? Why "kind of"?

Because I did not read the Pygments code. And this is actually based on Chroma ... although I did not read that code either.

Chroma has taken most of the Pygments lexers and turned them into XML descriptions. What I did was take those XML files from Chroma and a pile of test cases from Pygments, and I slapped them together until the tests passed and my code produced the same output as Chroma. Think of it as extreme TDD.

Currently the pass rate for tests in the supported languages is 96.8%, which is not bad for a couple days hacking.

This only covers the RegexLexers, which are the most common ones, but it means the supported languages are a subset of Chroma's, which is a subset of Pygments'.

Currently Tartrazine supports ... 241 languages.

It has 332 themes (64 from Chroma, the rest are base16 themes via Sixteen

Installation

This will have a CLI tool that can be installed, but it's not there yet.

Usage

This works:

require "tartrazine"

lexer = Tartrazine.lexer("crystal")
theme = Tartrazine.theme("catppuccin-macchiato")
puts Tartrazine::Html.new.format(File.read(ARGV[0]), lexer, theme)

Contributing

  1. Fork it (https://github.com/ralsina/tartrazine/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors