tartrazine/README.md

66 lines
1.9 KiB
Markdown
Raw Normal View History

2024-08-05 00:44:23 +00:00
# TARTRAZINE
2024-08-02 20:03:39 +00:00
2024-08-05 00:44:23 +00:00
Tartrazine is a library to syntax-highlight code. It is
2024-08-04 23:36:35 +00:00
a port of [Pygments](https://pygments.org/) to
[Crystal](https://crystal-lang.org/). Kind of.
2024-08-06 20:01:14 +00:00
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
2024-08-04 23:36:35 +00:00
# A port of what? Why "kind of"?
Because I did not read the Pygments code. And this is actually
2024-08-05 00:44:23 +00:00
based on [Chroma](https://github.com/alecthomas/chroma) ...
2024-08-04 23:36:35 +00:00
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*.
2024-08-05 00:44:23 +00:00
Currently the pass rate for tests in the supported languages
2024-08-05 00:38:00 +00:00
is `96.8%`, which is *not bad for a couple days hacking*.
2024-08-04 23:36:35 +00:00
This only covers the RegexLexers, which are the most common ones,
2024-08-05 00:44:23 +00:00
but it means the supported languages are a subset of Chroma's, which
2024-08-04 23:36:35 +00:00
is a subset of Pygments'.
Currently Tartrazine supports ... 241 languages.
2024-08-02 20:03:39 +00:00
2024-08-06 21:31:29 +00:00
It has 332 themes (64 from Chroma, the rest are base16 themes via
[Sixteen](https://github.com/ralsina/sixteen)
2024-08-02 20:03:39 +00:00
## Installation
2024-08-06 20:01:14 +00:00
This will have a CLI tool that can be installed, but it's not
there yet.
2024-08-02 20:03:39 +00:00
## Usage
2024-08-06 20:01:14 +00:00
This works:
2024-08-02 20:03:39 +00:00
2024-08-06 20:01:14 +00:00
```crystal
require "tartrazine"
2024-08-02 20:03:39 +00:00
2024-08-06 20:01:14 +00:00
lexer = Tartrazine.lexer("crystal")
theme = Tartrazine.theme("catppuccin-macchiato")
puts Tartrazine::Html.new.format(File.read(ARGV[0]), lexer, theme)
```
2024-08-02 20:03:39 +00:00
## Contributing
2024-08-04 23:36:35 +00:00
1. Fork it (<https://github.com/ralsina/tartrazine/fork>)
2024-08-02 20:03:39 +00:00
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
2024-08-04 23:36:35 +00:00
- [Roberto Alsina](https://github.com/ralsina) - creator and maintainer