Home

Awesome

<h1 align="center">Inkjet</h1> <h3 align="center">A batteries-included syntax highlighting library for Rust, based on <code>tree-sitter</code>.</h3> <p align="center"> <img src=".github/logo.png" width="256"> </p> <p align="center"> <img src="https://img.shields.io/crates/v/inkjet"> <img src="https://img.shields.io/github/actions/workflow/status/SomewhereOutInSpace/inkjet/rust.yml"> <img src="https://img.shields.io/crates/l/inkjet"> </p>

Features

Included Languages

Inkjet comes bundled with support for over seventy languages, and it's easy to add more - see the FAQ section.

<details> <summary><strong style="cursor: pointer">Click to expand...</strong></summary>
NameRecognized Tokens
Adaada
Assembly (generic)asm
Awkawk
Bashbash, sh, shell
BibTeXbibtex, bib
Bicepbicep
Blueprintblueprint, blp
Cc, h
Cap'N Protocapnp
Clojureclojure, clj, cljc
C#c_sharp, c#, csharp, cs
C++c++, cpp, hpp, h++, cc, hh
CSScss
Cuecue
Dd, dlang
Dartdart
Diffdiff
Dockerfiledockerfile, docker
EExeex
Emacs Lispelisp, emacs-lisp, el
Elixirex, exs, leex
Elmelm
Erlangerl, hrl, es, escript
Forthforth, fth
Fortranfortran, for
Fishfish
GDScriptgdscript, gd
Gleamgleam
GLSLglsl
Gogo, golang
Haskellhaskell, hs
HCLhcl, terraform
HEExheex
HTMLhtml, htm
INIini
JavaScriptjavascript, js
JSONjson
JSXjsx
Juliajulia, jl
Kotlinkotlin, kt, kts
LaTeXlatex, tex
LLVMllvm
Lualua
GNU Makemake, makefile, mk
MatLabmatlab, m
Mesonmeson
Nixnix
Objective Cobjective_c, objc
OCamlocaml, ml
OCaml Interfaceocaml_interface, mli
OpenSCADopenscad, scad
Pascalpascal
PHPphp
ProtoBufprotobuf, proto
Pythonpython, py
Rr
Racketracket, rkt
Regexregex
Rubyruby, rb
Rustrust, rs
Scalascala
Schemescheme, scm, ss
SCSSscss
SQL (Generic)sql
Swiftswift
TOMLtoml
TypeScripttypescript, ts
TSXtsx
Vimscriptvimscript, vim
WAST (WebAssembly Script)wast
WAT (WebAssembly Text)wat, wasm
x86 Assemblyx86asm, x86
WGSLwgsl
YAMLyaml
Zigzig
</details>

In addition to these languages, Inkjet also offers the Runtime and Plaintext languages.

Cargo Features

FAQ

"Why is Inkjet so large?"

Parser sources generated by tree-sitter can grow quite big, with some being dozens of megabytes in size. Inkjet has to bundle these sources for all the languages it supports, so it adds up. (According to loc, there are over 23 million lines of C code!)

If you need to minimize your binary size, consider disabling languages that you don't need. Link-time optimization can also shave off a few megabytes.

"Why is Inkjet taking so long to build?"

Because it has to compile and link in dozens of C/C++ programs (the parsers and scanners for every language Inkjet bundles.)

However, after the first build, these artifacts will be cached and subsequent builds should be much faster.

"Why does highlighting require a mutable reference to the highlighter?

Under the hood, Inkjet creates a tree-sitter highlighter/parser object, which in turn dynamically allocates a chunk of working memory. Using the same highlighter for multiple simultaneous jobs would therefore cause all sorts of nasty UB.

If you want to highlight in parallel, you'll have to create a clone of the highlighter for each thread. I recommend thread_local! and RefCell if you need a quick and easy solution.

"A language I want to highlight isn't bundled with Inkjet!"

Assuming that you or someone else has implemented a highlighting-ready tree-sitter grammar for the language you want, adding it to Inkjet is easy! Just open an issue asking for it to be added, linking to the grammar repository for the language.

Alternatively, you can use Language::Runtime, which will allow you to use grammars not bundled with Inkjet.

Other notes:

Building

For normal use, Inkjet will compile automatically just like any other crate.

However, if you have forked the repository and want to update the bundled languages, you'll need to use GNU Make with the included Makefile:

If, for whatever reason, you don't have GNU Make available: you can also perform these actions manually by setting the appropriate environment variables and Cargo flags:

Acknowledgements