rouge-ruby / rouge

A pure Ruby code highlighter that is compatible with Pygments
https://rouge.jneen.net/
Other
3.3k stars 732 forks source link

Typescript, adding keywords satisfies and as to the lexer #2014

Closed Eunoia closed 1 month ago

Eunoia commented 6 months ago

Howdy!

Noticed some less than perfect syntax highlighting on a blog post, and thought to fix the issue upstream in rouge.

In typescript, 'as' and 'satisfies' are type assertion operator, while 'satisfies' is a type operator. There is no 'as' keyword in javascript, and the way the rule was written, functions named "as" were being marked as keywords, rather than functions.

I took the rule from a textmate grammar, and modified it to work in rouge.

I also tested this commit against my blog, and noticed the improved syntax highlighting there.

Now, "satisfies" and "as" are marked as keywords where they are used in a keyword way.

Here are three screenshots, before, after, and delta of visual lexer test.

Before

The "satisfies" is not bolded, and the "as" in the function names are bolded. Not ideal.

Screenshot 2023-12-09 at 5 19 53 PM

After

The "satisfies" is bolded, and the function names are not bolded, with no regressions to the other "as"

Screenshot 2023-12-09 at 5 19 13 PM

Delta

white is unchanged, teal is text that was made unbolded, and yellow is bolded.

Screenshot 2023-12-10 at 10 58 35 AM
tancnle commented 1 month ago

Thanks, @Eunoia. Change LGTM 🚀