feat: add Nix syntax highlighting (#3110)

* feat: add Nix syntax highlighting

* fix: update Nix dependency hash

* fix: update Nix dependency hash

---------

Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
This commit is contained in:
James Strain
2026-08-17 13:17:53 +02:00
committed by GitHub
co-authored by Mohamed Boudra
parent 0eab0b7828
commit c8b2c8351f
6 changed files with 36 additions and 2 deletions
@@ -75,6 +75,17 @@ describe("highlightCode", () => {
expect(stringToken?.style).toBe("string");
});
it("highlights Nix code", () => {
const code = 'let message = "hello"; in message';
const result = highlightCode(code, "default.nix");
const letToken = result[0].find((token) => token.text === "let");
expect(letToken?.style).toBe("keyword");
const stringToken = result[0].find((token) => token.text.includes("hello"));
expect(stringToken?.style).toBe("string");
});
it("highlights TSX code with correct dialect", () => {
const code = 'const el = <div className="test">hello</div>;';
const result = highlightCode(code, "test.tsx");
@@ -21,6 +21,7 @@ describe("isLanguageSupported", () => {
expect(isLanguageSupported("test.swift")).toBe(true);
expect(isLanguageSupported("test.dart")).toBe(true);
expect(isLanguageSupported("test.cs")).toBe(true);
expect(isLanguageSupported("test.nix")).toBe(true);
expect(isLanguageSupported("test.ex")).toBe(true);
});
@@ -60,6 +61,7 @@ describe("getSupportedExtensions", () => {
expect(extensions).toContain("swift");
expect(extensions).toContain("dart");
expect(extensions).toContain("cs");
expect(extensions).toContain("nix");
expect(extensions).toContain("json");
});
});
+3
View File
@@ -15,6 +15,7 @@ import { parser as rustParser } from "@lezer/rust";
import { parser as xmlParser } from "@lezer/xml";
import { parser as yamlParser } from "@lezer/yaml";
import { csharpLanguage } from "@replit/codemirror-lang-csharp";
import { nixLanguage } from "@replit/codemirror-lang-nix";
import { parser as elixirParser } from "lezer-elixir";
import type { Parser } from "@lezer/common";
@@ -69,6 +70,8 @@ const languagesByExtension: Record<string, Language> = {
dart: StreamLanguage.define(dart),
// C#
cs: csharpLanguage,
// Nix
nix: nixLanguage,
// Elixir
ex: language(elixirParser),
exs: language(elixirParser),