Created lexers for gjs and gts (used by Ember projects)#2165
Merged
tancnle merged 14 commits intorouge-ruby:masterfrom Nov 7, 2025
ijlee2:support-gjs-and-gts
Merged
Created lexers for gjs and gts (used by Ember projects)#2165tancnle merged 14 commits intorouge-ruby:masterfrom ijlee2:support-gjs-and-gts
tancnle merged 14 commits intorouge-ruby:masterfrom
ijlee2:support-gjs-and-gts
Conversation
ijlee2
commented
Sep 25, 2025
Contributor
Author
|
To the reviewers: I fixed the lint errors found in CI (new line missing at EOF). Will move the PR to draft so that @dknutsen from #2163 can look into adding specs to this branch. |
…t, and typescript
* fix: update regex to correctly delegate handlebars in gjs and gts lexers * chore: update demo to include javascript after the closing template tag * chore: update demo to include typescript after the closing template tag * test: add guessing test for gjs and gts lexer
This reverts commit a9953db.
…avascript, and typescript" This reverts commit 25eddf1.
This reverts commit 7822430.
…an existing bug in the handlebars lexer causes tests to fail
Contributor
Author
|
@tancnle Could you help with reviewing this pull request? |
Contributor
|
@tancnle is there anything we can do to help move this forward? |
|
+1 |
Collaborator
|
Apology for the delay. Thank you for your work on this MR, @ijlee2. LGTM 🚀 |
Contributor
Author
|
@tancnle Thank you again for your help! Q. When could we expect a new release in |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
This pull request (PR) provides a simpler, more maintainable implementation than #2163.
In Ember.js, we use the extension
*.gjsand*.gtsto write JavaScript/TypeScript and template code in the same file. Templates are marked by a<template>tag. The main use case of*.{gjs,gts}: Developers can write single-file components, an idea that we can find in other web frameworks.To my understanding, GitLab and dev.to rely on
rougefor syntax highlighting. This PR would especially help developers who use GitLab, because they currently can't see diffs in*.{gjs,gts}highlighted in their PRs.Related issues on GitLab:
Solution
*.gjsand*.gtsare just JavaScript and TypeScript with some Handlebars-like code (technically, it's Glimmer). As a result, I believe the best solution is to delegate syntax highlighting to existingjavascript,typescript, andhandlebarslexers, since they've been tested out for years (not just in the context of Ember, but also of others).The new
gjsandgtslexers are only responsible for locating the starting<template>and the ending</template>tags. As an aside, I've used this separation of concerns successfully to implement syntax highlighting for Sublime Text.Note
There's a possibility that, in the future,
*.{gjs,gts}allows the<style>tag in addition to the<template>tag. The Ember community hasn't come to a consensus on where this tag should appear and how it should be invoked. So, to limit the scope, I allowed thegjsandgtslexers to not handle the<style>tag for now.Demos (Testing)
In the screenshots below, we should see the JavaScript part of a
*.gjsfile highlighted in the same manner as in a*.jsfile. Similarly, the TypeScript part of a*.gtsfile, as in a*.tsfile. In both*.gjsand*.gts, the template code inside a<template>tag should be highlighted as if it were in an*.hbsfile.Example 1: Component
gjs, theme is default
gjs, theme is github
gjs, theme is github-dark
gts, theme is default
gts, theme is github
gts, theme is github-dark
Example 2: Test for the component
gjs, theme is default
gjs, theme is github
gjs, theme is github-dark
gts, theme is default
gts, theme is github
gts, theme is github-dark