Crate two_face

source ·
Expand description

Dedicated to chasing the bat man

Extra syntax and theme definitions for syntect including many common ones that are missing from the default set like TOML, TypeScript, and Dockerfile. Curated by the bat Project

§Example

The following

$ cargo add two-face --features syntect-default-onig
use two_face::re_exports::syntect;

const TOML_TEXT: &str = "\
[section]
key = 123
";

fn main() {
    let syn_set = two_face::syntax::extra_newlines();
    let theme_set = two_face::theme::extra();

    let syn_ref = syn_set.find_syntax_by_extension("toml").unwrap();
    let theme = theme_set.get(two_face::theme::EmbeddedThemeName::Nord);
    let htmlified = syntect::html::highlighted_html_for_string(
        TOML_TEXT,
        &syn_set,
        syn_ref,
        theme
    ).unwrap();

    // Where `htmlified` displays as vv
}

where htmlified displays as

[section]
key = 123

§Feature Flags

The feature flags are divided by syntect’s underlying regex implementation with Oniguruma aka onig being the default and fancy-regex aka fancy as an alternative pure-Rust implementation. fancy: however, doesn’t support all of the features used by some of the syntax definitions, so some of the defintions are excluded when fancy is selected* to keep the regex compilation infallible. This means that it’s important to match whichever regex implementation syntect is using

* This is also why fancy’s bundled syntax definitions are smaller than onig’s

default: syntect-onig

FeatureDesc.
syntect-onig / syntect-fancyEnables the minimal feature set that we require from syntect
syntect-default-onig / syntect-default-fancyThe mimimal feature sets along with syntect’s default feature set (useful when using the syntect re-export)

§Embedded Asset Sizes

This crate embeds some reasonably large assets in the final binary in order to work. Luckily the linker is smart enough to discard unused assets, so you generally only pay for what you use

For reference here are the sizes associated with their different functions

functiontwo-face (KiB)syntect (KiB)
acknowledgement::listing()10-
syntax::extra_newlines() (onig)859360
^^ (fancy)804360
syntax::extra_no_newlines() (onig)858359
^^ (fancy)803359
theme::extra()455

In short the syntax definitions are the real chonky part, and if you’re switching from syntect to two-face, then you can expect a ~0.5MiB increase in binary size from them (in exchange for a lot of syntax definitions)

§Syntaxes

The full listing of all syntaxes included in syntax

  • * Exluded when using the fancy-regex implementation
  • † Included in syntect’s bundled defaults
Syntax Definition
AActionScript†, Ada, Apache Conf, AppleScript†, AsciiDoc, ASP†, ARM Assembly*, Assembly (x86_64), AWK
BBash†, Batch File†, BibTeX†
CC†, C#†, C++†, Cabal, Clojure†, CMake, CoffeeScript, Crontab, Crystal, CSS†, CSV†
DD†, Dart, Dockerfile, DotENV, Diff†
EElixir, Elm, Email, Erlang†
FF#, Fish, Fortran, fstab
GGit (commit, config, ignore, etc.)†, GLSL, Go†, GraphQL, Graphviz (DOT)†, Groff/troff†, Groovy†
HHaskell†, HTML†
IINI
JJava†, Javadoc†, Java Server Page (JSP)†, JavaScript†, JavaScript (Babel)*, Jinja2, JQ, JSON†, Julia
KKotlin
LLaTeX†, LaTeX Log†, Lean, LESS, Lisp†, Literate Haskell†, LiveScript*, LLVM, Lua†
MMakefile†, Manpage, Markdown†, MATLAB†, Mediawiki, MutliMarkdown†
NNAnt Build File†, Nginx, Nim, Ninja, Nix
OObjective-C†, Objective-C++†, OCaml†, OCamllex†, OCamlyacc†, Org Mode
PPascal†, Perl†, PHP†, PowerShell*, Protobuf, Puppet, PureScript, Python†
QQML
RR†, Racket, Rd†, Rego, Regular Expression†, Requirements.txt, reStructuredText†, Robot Framework, Ruby†, Ruby Haml†, Ruby on Rails†, Ruby Slim, Rust†
SSass*, Scala†, SCSS, Salt State SLS*, SML, Solidity, SQL†, Strace, Stylus, Svelte, Swift, SystemVerilog
TTcl†, Terraform, TeX†, Textile†, Todo.txt, TOML, TypeScript, TypescriptReact
VVarlink, Verilog, VimL, Vue, Vyper
XXML†
YYAML†
ZZig

§Themes

Note: For visual examples of all of the embedded themes look at the docs for theme::EmbeddedThemeName

The full listing of themes provided by theme. Many of these themes only make sense situationally, so you’ll likely want to only expose a subset

  • † Included in syntect’s bundled defaults
Theme
11337 (aka leet)
AAnsi
BBase16, Base16-256, Base16-Eighties (dark)†, Base16-Mocha (dark)†, Base16-Ocean (light/dark)†
CColdark (cold/dark aka light/dark)
DDarkNeon, Dracula
GGitHub, gruvbox (light/dark)
IInspiredGitHub†
MMonokai Extended (plain, bright, light, and origin)
NNord
OOne Half (light/dark)
SSolarized (light/dark)†
TTwoDark
VVisual Studio Dark+
ZZenburn

The embedded syntax definitions and assets also have their own licenses which are compiled into this markdown file along with programmatic in the acknowledgement module

Modules§

  • Contains acknowledgements for embedded data and all of their associated types
  • Dependency re-exports for user’s convenience
  • Contains extra syntax definitions
  • Contains extra theme definitions and the LazyThemeSet type

Functions§

  • Returns a link to a page listing acknowledgements for all syntax and theme definitions