typst/vendor/two-face
2024-10-16 14:18:46 +03:00
..
generated 0.11.1-alt1 2024-10-16 14:18:46 +03:00
src 0.11.1-alt1 2024-10-16 14:18:46 +03:00
.cargo-checksum.json 0.11.1-alt1 2024-10-16 14:18:46 +03:00
Cargo.toml 0.11.1-alt1 2024-10-16 14:18:46 +03:00
CHANGELOG.md 0.11.1-alt1 2024-10-16 14:18:46 +03:00
LICENSE-APACHE 0.11.1-alt1 2024-10-16 14:18:46 +03:00
LICENSE-MIT 0.11.1-alt1 2024-10-16 14:18:46 +03:00
README.md 0.11.1-alt1 2024-10-16 14:18:46 +03:00

two-face

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

Example

The following

[dependencies]
syntect = "0.5.1"
two-face = "0.2.0"
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();

    println!("{htmlified}");
}

will print this

<pre style="background-color:#2e3440;">
<span style="color:#d8dee9;">[section]
</span><span style="color:#81a1c1;">key </span><span style="color:#d8dee9;">= </span><span style="color:#b48ead;">123
</span></pre>

Feature Flags

Some embedded syntaxes use features that aren't available with fancy-regex. To keep regex compilation infallible it's important to match this library's regex implementation with the one you're using from syntect

To use Oniguruma aka onig

[dependencies]
# `onig` is the default
syntect = "0.5.1"
two-face = "0.2.0"

To use fancy-regex

[dependencies]
syntect = { version = "0.5.1", default-features = false, features = ["default-fancy"] }
two-face = { version = "0.2.0", default-features = false, features = ["syntect-fancy"] }

Most of the code for generating the syntax and theme dumps along with curating said syntax and themes is taken from bat. Because of this we also mirror bat's licenses by being dual licensed under MIT and Apache-2.0.

See the LICENSE-APACHE and LICENSE-MIT files for license details.

bat's NOTICE

Copyright (c) 2018-2021 bat-developers (https://github.com/sharkdp/bat).

bat is made available under the terms of either the MIT License or the Apache License 2.0, at your option.

See the LICENSE-APACHE and LICENSE-MIT files for license details.