syntect icon indicating copy to clipboard operation
syntect copied to clipboard

Add nix syntax support

Open Septias opened this issue 1 year ago • 2 comments

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

Septias avatar Mar 11 '24 10:03 Septias

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:

  • https://github.com/trishume/syntect/issues/168
  • https://github.com/trishume/syntect/issues/418

keith-hall avatar Mar 11 '24 19:03 keith-hall

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

CosmicHorrorDev avatar Mar 16 '24 17:03 CosmicHorrorDev