Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nix syntax support #523

Open
Septias opened this issue Mar 11, 2024 · 2 comments
Open

Add nix syntax support #523

Septias opened this issue Mar 11, 2024 · 2 comments

Comments

@Septias
Copy link

Septias commented Mar 11, 2024

Can you add the nix language as supported language?

It has a syntax definition file here: https://github.com/bbenoist/vscode-nix/blob/master/syntaxes/nix.tmLanguage

@keith-hall
Copy link
Collaborator

syntect is just a library, which happens to come with some language syntax support by default (which is unlikely to change much), but there's nothing to stop users of the library from using whatever languages they want...

see also:

@CosmicHorrorDev
Copy link
Contributor

Nix is one of the extra syntax definitions that gets bundled in with two-face. E.g.

[package]
name = "demo"
version = "0.1.0"
edition = "2021"

[dependencies]
syntect = "5.2.0"
two-face = "0.3.0"
const NIX_TEXT: &str = r#"{ lib }:

let
  defaultSourceType = tname: {
    shortName = tname;
    isSource = false;
  };
in lib.mapAttrs (tname: tset: defaultSourceType tname // tset) {

  fromSource = {
    isSource = true;
  };

  binaryNativeCode = {};

  binaryBytecode = {};

  binaryFirmware = {};
}"#;

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("nix").unwrap();
    let theme = theme_set.get(two_face::theme::EmbeddedThemeName::Nord);
    let htmlified =
        syntect::html::highlighted_html_for_string(NIX_TEXT, &syn_set, syn_ref, theme).unwrap();

    println!("{htmlified}");
}

prints out HTML that renders as vv in my browser

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants