Skip to content

Conversation

@ijlee2
Copy link
Contributor

@ijlee2 ijlee2 commented Sep 25, 2025

Background

This pull request (PR) provides a simpler, more maintainable implementation than #2163.

In Ember.js, we use the extension *.gjs and *.gts to 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 rouge for 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

*.gjs and *.gts are 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 existing javascript, typescript, and handlebars lexers, since they've been tested out for years (not just in the context of Ember, but also of others).

The new gjs and gts lexers 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 the gjs and gts lexers to not handle the <style> tag for now.

Demos (Testing)

In the screenshots below, we should see the JavaScript part of a *.gjs file highlighted in the same manner as in a *.js file. Similarly, the TypeScript part of a *.gts file, as in a *.ts file. In both *.gjs and *.gts, the template code inside a <template> tag should be highlighted as if it were in an *.hbs file.

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

@ijlee2 ijlee2 marked this pull request as ready for review September 25, 2025 08:10
@ijlee2 ijlee2 marked this pull request as draft October 2, 2025 14:12
@ijlee2
Copy link
Contributor Author

ijlee2 commented Oct 2, 2025

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.

@ijlee2 ijlee2 force-pushed the support-gjs-and-gts branch from 8ce53b5 to 36883f3 Compare October 3, 2025 03:42
* chore: Copied specs from #2163

* refactor: Extracted specs for lexing

---------

Co-authored-by: Dan Knutsen <dknutsen@gmail.com>
@ijlee2 ijlee2 marked this pull request as ready for review October 6, 2025 07:59
@ijlee2
Copy link
Contributor Author

ijlee2 commented Oct 6, 2025

Hi, this PR is ready for review again. @dknutsen, @lukasnys, and I'd like to get #2165 reviewed and merged (instead of #2163). Thanks in advance.

@ijlee2
Copy link
Contributor Author

ijlee2 commented Oct 13, 2025

@tancnle Could you help with reviewing this pull request?

@tancnle tancnle self-requested a review October 13, 2025 12:08
@tancnle tancnle added the needs-review The PR needs to be reviewed label Oct 13, 2025
@lukasnys
Copy link
Contributor

lukasnys commented Nov 3, 2025

@tancnle is there anything we can do to help move this forward?

@BoussonKarel
Copy link

+1

@tancnle
Copy link
Collaborator

tancnle commented Nov 7, 2025

Apology for the delay. Thank you for your work on this MR, @ijlee2. LGTM 🚀

@tancnle tancnle added this pull request to the merge queue Nov 7, 2025
Merged via the queue into rouge-ruby:master with commit debef62 Nov 7, 2025
10 checks passed
@ijlee2 ijlee2 deleted the support-gjs-and-gts branch November 7, 2025 06:39
@ijlee2
Copy link
Contributor Author

ijlee2 commented Nov 7, 2025

@tancnle Thank you again for your help!

Q. When could we expect a new release in rouge? Do we then notify people on GitLab in https://gitlab.com/gitlab-org/gitlab/-/issues/573281?

@lukasnys
Copy link
Contributor

lukasnys commented Dec 8, 2025

@tancnle I'm not sure if you had seen @ijlee2's comment (apologies if you did), but would you be able to give an estimate on when this change would be included in a new release of rouge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review The PR needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants