Skip to content

Extend syntax highlighting to TypeScript, JSX, and .mjs/.cjs - #9

Merged
stojanovic merged 4 commits into
mainfrom
claude/amazing-sagan-vl2d4m
Jun 8, 2026
Merged

Extend syntax highlighting to TypeScript, JSX, and .mjs/.cjs#9
stojanovic merged 4 commits into
mainfrom
claude/amazing-sagan-vl2d4m

Conversation

@stojanovic

Copy link
Copy Markdown
Owner

syntect's default pack covers Rust, Python, JavaScript, and CSS but not
TypeScript, TSX, JSX, or the .mjs/.cjs Node.js variants — those rendered
plain. Pull in two-face for the TS/TSX (and SCSS, etc.) grammars, and
alias .mjs/.cjs/.jsx → js and .mts/.cts → ts so Node.js and JSX sources
highlight via the existing JavaScript/TypeScript syntaxes.

claude added 2 commits June 8, 2026 18:54
syntect's default pack covers Rust, Python, JavaScript, and CSS but not
TypeScript, TSX, JSX, or the .mjs/.cjs Node.js variants — those rendered
plain. Pull in `two-face` for the TS/TSX (and SCSS, etc.) grammars, and
alias .mjs/.cjs/.jsx → js and .mts/.cts → ts so Node.js and JSX sources
highlight via the existing JavaScript/TypeScript syntaxes.
The two-face syntax pack already covers JSON, YAML, TOML, Markdown, HTML,
Bash, Go, Java, C/C++, Ruby, SQL, Kotlin, Swift, Scala, Dockerfile, GraphQL,
SCSS, Vue, Svelte, Protobuf, Terraform, Lua, Dart, Elixir and many more —
add a regression test that asserts every one of them highlights. Alias the
two notable JSON dialects (jsonc, json5) to json so commented JSON files
still render.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the diff renderer’s syntax highlighting by switching from syntect’s default syntax pack to two-face’s extended syntax set, and by aliasing several file extensions (notably Node.js and TS variants) to syntaxes that syntect can highlight.

Changes:

  • Replace SyntaxSet::load_defaults_newlines() with two_face::syntax::extra_newlines() to gain additional syntaxes (e.g., TypeScript/TSX, SCSS).
  • Add an alias_extension() mapping so .mjs/.cjs/.jsx highlight as JavaScript and .mts/.cts highlight as TypeScript (plus JSONC/JSON5 → JSON).
  • Add a broad test intended to validate highlighting across many extensions.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/render/highlight.rs Uses two-face syntaxes, introduces extension aliasing, and adds new highlighting tests.
Cargo.toml Adds the two-face dependency with syntect “fancy” highlighting support.
Cargo.lock Locks the new two-face transitive dependency set.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Cargo.toml
Comment on lines +25 to +27
# Extra syntect syntaxes covering languages syntect ships without — notably
# TypeScript/TSX, JSX, and modern Node.js extensions (.mjs/.cjs).
two-face = { version = "0.5", default-features = false, features = ["syntect-fancy"] }
Comment thread src/render/highlight.rs Outdated
Comment on lines +117 to +125
fn highlights_the_supported_languages() {
let h = Highlighter::new();
// syntect's default pack covers Rust, Python, JavaScript, CSS, JSON,
// YAML, TOML, Markdown, HTML, Bash, Go, Java, C/C++, Ruby, SQL, etc.
// `two-face` adds TypeScript/TSX, SCSS, Dockerfile, GraphQL, Vue,
// Svelte, Protobuf, Terraform, Kotlin, Swift, Zig, Dart, Elixir and
// more. The remaining extensions are aliased to a sibling syntax so
// Node.js (.mjs/.cjs), JSX, and JSON-with-comments still highlight.
for (ext, line) in [
Comment thread src/render/highlight.rs Outdated
Comment on lines +15 to +17
/// Map extensions syntect (even with `two-face`'s extras) doesn't recognise to
/// a sibling syntax — keeping JSX and modern Node.js extensions highlighted as
/// JavaScript.
claude added 2 commits June 8, 2026 19:33
- Cargo.toml: tighten the two-face comment to only claim what the crate
  actually adds (TypeScript/TSX); the JSX and .mjs/.cjs cases are aliased,
  not provided by the syntax pack.
- highlight: expand the alias_extension doc comment to cover .mts/.cts
  and jsonc/json5, not just JSX and Node.js.
- highlight: narrow the language-coverage test to the extensions whose
  support this module is responsible for (ts/tsx plus the aliased ones,
  with rs as a baseline). The previous list reached into syntect/two-face's
  bundled grammars (lua, dart, elixir, svelte, …), which would have made
  the test brittle to dependency reshuffles.
@stojanovic
stojanovic merged commit 0d2b550 into main Jun 8, 2026
1 check passed
@stojanovic
stojanovic deleted the claude/amazing-sagan-vl2d4m branch June 8, 2026 19:40
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

Successfully merging this pull request may close these issues.

3 participants