Skip to content

Languages

Comfit identifies languages by an ID such as javascript or an alias such as js. Each language has a Tree-sitter grammar for parsing source and queries that assign syntax capture names. Themes turn those captures into token styles.

Use this guide to find a language, include it in your application, and check which embedded languages it can request. For installation and a first render, start with your environment's quickstart.

Find a language

The language catalog lists all registered languages, including helper grammars used inside other languages. Use an ID or one of its aliases when highlighting. A display name or file extension is not necessarily an accepted language name.

To list the languages available in a bundled package:

JavaScript
JavaScript
import { languages } from "@comfit/node";

console.log(languages());

The CLI can infer a language from a filename. In library calls, pass the language ID or alias explicitly.

Choose which languages to include

Node.js, Python, rehype, and the CLI bundle the registered languages. Rust applications select languages at build time through Cargo features. Browser applications load the parser assets they need when creating a highlighter.

Select Rust grammars

Enable language features on comfit:

Shell
cargo add comfit --features rust,javascript,render-html

This includes Rust and JavaScript with HTML rendering. No languages are enabled by default.

Use all-languages to include every bundled language. Features generally use the IDs in the catalog, including underscores in names such as c_sharp.

Enable embedded languages too. The markdown feature also enables markdown_inline, but a Rust code fence still needs the rust feature. See the Rust quickstart for a complete rendering example.

Load browser languages

Follow the browser quickstart to install @comfit/wasm and @comfit/wasm-grammars and initialize both runtimes. Then load a language descriptor and its parser WASM file:

TypeScript
import { createHighlighter } from "@comfit/wasm";
import rust from "@comfit/wasm-grammars/rust";
import rustWasm from "@comfit/wasm-grammars/tree-sitter-rust.wasm?url";

const highlighter = await createHighlighter({
  languages: [{ ...rust, wasm: rustWasm }],
});

try {
  console.log(highlighter.highlight("fn main() {}", "rust"));
} finally {
  highlighter.dispose();
}

The descriptor contains the language ID, aliases, and queries. The WASM file contains the parser.

Importing the descriptor alone does not fetch the parser. createHighlighter loads the asset and registers the language.

This example uses Vite's ?url imports. With another build tool, serve the parser as a public asset and set wasm to its URL. Keep @comfit/wasm and @comfit/wasm-grammars versions matched.

Descriptor import paths use hyphens where language IDs use underscores. For example, import @comfit/wasm-grammars/markdown-inline for the markdown_inline language.

Parser filenames use the grammar's name, which can differ from the language ID. JSX shares JavaScript's parser, for example. Use the descriptor's asset reference or explicitly supply the correct parser URL.

Include embedded languages

An injection is a region of source highlighted with another grammar. Markdown with Rust code fences needs markdown, markdown_inline, and rust.

In the browser, pass all three descriptors to createHighlighter. In Rust, enable markdown and rust.

An unloaded root language is an error. An unloaded embedded language is skipped, leaving the outer language's styling in place. A fence label or alias does not load a parser automatically.

The catalog's injection column shows direct targets, not the full dependency chain. Follow those targets if you want their embedded content highlighted too. For example, JavaScript can request HTML, which can in turn request CSS or another script language.

See Embedded languages for a complete browser registration example and injection-query behavior.

Use parsers and queries directly

Most applications only need comfit or @comfit/wasm. Use comfit-grammars when building a Rust integration that needs parser entry points and query strings:

Shell
cargo add comfit-grammars --features rust

The rust module exposes LANGUAGE, HIGHLIGHTS_QUERY, INJECTIONS_QUERY, LOCALS_QUERY, and RAINBOWS_QUERY. See the grammar crate reference for Rust and the Language descriptor reference for browser integrations.

Language catalog

The catalog follows registry/languages.toml and the resolved bundled injection queries, including inherited queries. File associations list registered extensions and filenames. Languages without file associations are often helper grammars used through injections.

The Injection languages column uses language IDs:

  • Named targets are explicitly selected by a query or by a constrained language capture.
  • Source-selected means a query reads a language name from source, such as a code-fence label, heredoc delimiter, template tag, or lang attribute. The query may restrict which names it accepts. Only registered, loaded targets can be highlighted.
  • Parent language means an injected region requests the language that contains its current layer. A language may also inject itself.
  • None means the bundled query has no direct injection targets. It does not describe languages that might inject this one.

These are query rules, not a promise that every string or comment matching a language name will be treated as embedded code. Custom queries can change the targets.

LanguageIDAliasesFile extensions / namesInjection languages
AngularangularNoneNonecomment, css, javascript, json, regex, Source-selected
Assemblyasmassembly, gasscomment
AstroastroNoneastrocomment, css, javascript, json, regex, scss, typescript, Source-selected
Bashbashsh, shellsh, bashbash, comment, printf, readline, regex, Source-selected
BibTeXbibtexbibbibcomment
CcNonec, hasm, c, comment, doxygen, printf, re2c
C#c_sharpcsharp, cs, c#cscomment
C++cppc++, cc, cxxcpp, cc, cxx, hpp, hh, hxxasm, comment, cpp, doxygen, printf, re2c, Source-selected
C3c3Nonec3, c3i, c3tcomment
CMakecmakeNonecmake, CMakeLists.txtcomment
CommentcommentNoneNoneNone
CSScssNonecsscomment
CSVcsvNonecsvNone
CUDAcudaNonecu, cuhasm, comment, cuda, doxygen, printf, re2c, Source-selected
DartdartNonedartcomment
Diffdiffpatchdiff, patchcomment
Dockerfiledockerfilecontainerfile, docker, containerdockerfile, containerfile, docker, containerbash, comment, json, toml, xml, yaml
DoxygendoxygenNoneNonehtml, Source-selected, Parent language
DTDdtdNonedtdcomment
EExeexNoneeexelixir, html
Elixirelixirexex, exscomment, eex, heex, json, markdown, regex, surface, zig
Erlangerlangerlerl, hrlcomment
F#fsharpf#, fsfs, fsxcomment, xml
FishfishNonefishcomment
FortranfortranNonef, for, f90, f95, f03, f08, f18, fppcomment
GDScriptgdscriptNonegdcomment
Git AttributesgitattributesNonegitattributes, .gitattributescomment
Git Configgit_configgitconfiggitconfig, .gitconfigbash, comment
GleamgleamNonegleamcomment
Glimmerglimmerhbs, handlebarshbscomment, css, javascript
Gogogolanggocomment, printf, re2c, regex
GraphQLgraphqlgqlgraphql, gqlcomment
GROQgroqNonegroqcomment
Haskellhaskellhshscomment, css, graphql, haskell_persistent, html, javascript, json, python, sql, typescript, Source-selected
Haskell Persistenthaskell_persistentNoneNoneNone
HCLhclNonehclcomment, Source-selected
HEExheexNoneheexcomment, elixir
HTMLhtmlhtmhtml, htm, xhtmlcomment, css, javascript, json, python, regex, toml, Source-selected
HTTPhttpNonehttp, restcomment, graphql, javascript, json, xml, Source-selected
INIinidosiniini, cfgcomment
JavajavaNonejavacomment, javadoc, printf
JavadocjavadocNoneNonehtml, markdown_inline, printf, Source-selected
JavaScriptjavascriptjs, ecmascript, x-javascriptjs, mjs, cjsangular, comment, css, glimmer, graphql, groq, html, jsdoc, regex, sql, styled, Source-selected
Jinjajinjajinja2, j2jinja, jinja2, j2comment, jinja_inline
Jinja Inlinejinja_inlineNoneNonecomment
JSDocjsdocNoneNoneNone
JSONjsonjsonc, jsonld, ld+jsonjson, jsonc, jsonldcomment
JSON5json5Nonejson5comment
JSXjsxNonejsxangular, comment, css, glimmer, graphql, groq, html, jsdoc, regex, sql, styled, Source-selected
Juliajuliajljlbash, comment, markdown, regex
Justjustjustfilejust, justfile, .justfilebash, comment, javascript, python, regex, Source-selected
KDLkdlNonekdlcomment
Kotlinkotlinkt, ktskt, ktscomment, printf, regex
LaTeXlatextextex, sty, cls, ltxc, comment, lua, python, Source-selected
LualuaNoneluac, comment, lua, luadoc, luap, printf, query, vim
Lua PatternluapNoneNoneNone
LuaDocluadocNoneNoneNone
Makemakemakefilemk, mak, Makefile, GNUmakefilebash, comment
Markdownmarkdownmdmd, markdownhtml, markdown_inline, toml, yaml, Source-selected
Markdown Inlinemarkdown_inlineNoneNoneNone
NASMnasmNoneasm, nasmcomment
NixnixNonenixbash, comment, fish, haskell, javascript, lua, perl, python, regex, rust, Source-selected
Nushellnunushellnucomment
OCamlocamlNonemlcomment
OCaml Interfaceocaml_interfaceNonemlicomment
OdinodinNoneodincomment
PasswdpasswdNonepasswdNone
PerlperlNonepl, pmcomment, perl, pod, Source-selected
PHPphpNonephp, phtmlbash, html, phpdoc, regex, Source-selected
PHPDocphpdocNoneNoneNone
PODpodNonepodNone
PowerShellpowershellps1, pwshps1, psm1, psd1comment, powershell, regex
PrintfprintfNoneNoneNone
PrismaprismaNoneprismacomment
PromQLpromqlNonepromqlcomment, regex
Protocol Buffersprotoprotobufprotocomment
PugpugNonepugcomment, javascript, Source-selected
Pythonpythonpypy, pyi, pywcomment, printf, regex
Rrrscriptr, rprofile, .Rprofilecomment
RBSrbsNonerbscomment
re2cre2cNonere2ccomment, Parent language
ReadlinereadlineNoneinputrccomment
RegexregexregexpNoneNone
Rubyrubyrbrb, rake, gemspeccomment, rbs, regex, ruby, Source-selected
Rustrustrsrscomment, html, json, re2c, regex, rust, slint, xml, Source-selected
ScalascalaNonescala, sccomment
SCSSscssNonescsscomment
SlintslintNoneslintcomment
SQLsqlNonesqlcomment
Styled ComponentsstyledNoneNonecomment, javascript
SurfacesurfaceNonesfacecomment, elixir
SveltesvelteNonesveltecomment, css, javascript, json, pug, regex, scss, typescript, Source-selected
SwiftswiftNoneswiftcomment, regex
Terraformterraformtf, opentofutf, tfvars, tofucomment, Source-selected
TOMLtomlNonetomlcomment
Tree-sitter Queryquerytsqueryscmcomment, luap, regex
TSXtsxNonetsxangular, comment, css, glimmer, graphql, groq, html, jsdoc, regex, sql, styled, Source-selected
TypeScripttypescriptts, x-typescriptts, mts, ctsangular, comment, css, glimmer, graphql, groq, html, jsdoc, regex, sql, styled, Source-selected
Typsttypsttyptypcomment, Source-selected
Vim Scriptvimvimscriptvim, vimrccomment, lua, perl, python, regex, ruby, vim
VuevueNonevuecomment, css, javascript, json, jsx, pug, regex, scss, tsx, typescript, Source-selected
WGSLwgslweslwgsl, weslcomment
XMLxmlNonexml, xsd, xsl, xslt, svgcomment, css, javascript, sql
YAMLyamlymlyaml, ymlbash, comment, promql
ZigzigNonezig, zoncomment