chroma icon indicating copy to clipboard operation
chroma copied to clipboard

application/javascript should be treated as `text/javascript`

Open markstos opened this issue 4 years ago • 4 comments

What problem does this feature solve?

Consider this script named monitor:

#!/usr/bin/env node
/* some JavaScript code here */

This gets detected with a MIME Type of application/javascript Chroma currently doesn't highlight it.

What feature do you propose?

Handle application/javascript the same as text/javascript

markstos avatar Feb 05 '21 18:02 markstos

Please send a PR.

alecthomas avatar Feb 05 '21 22:02 alecthomas

I'm not familiar with the project structure. Could you point me to the right file?

Thanks.

On Fri, Feb 5, 2021 at 5:09 PM Alec Thomas [email protected] wrote:

Please send a PR.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/alecthomas/chroma/issues/448#issuecomment-774314999, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAGJZK3DJ7WLR775LSTZVLS5RUBDANCNFSM4XFIDEXA .

--

Mark Stosberg (he/him)

Director of Systems & Security

[email protected] | 765.277.1916

https://www.rideamigos.com https://rideamigos.com/

Changing the way the world commutes.

https://www.linkedin.com/company/rideamigos https://www.twitter.com/rideamigos https://www.facebook.com/rideamigos https://www.instagram.com/rideamigos https://rideamigos.com/newsletter-sign-up/

markstos avatar Feb 12 '21 20:02 markstos

I'm not familiar with the project structure. Could you point me to the right file? Thanks.

From what I've gathered, application/javascript is already in the config of the js lexer. However, the internal MatchMimeType is only used here, not by the autodetect option of cmd.

When calling from the cmd, chroma uses mostly only the filename to determine the lexer, as can be seen here.

zhangyuannie avatar Apr 14 '21 05:04 zhangyuannie

Apologies, I didn't really comprehend this at the time. The issue is exactly what @zhangyuannie describes - Chroma does not have comprehensive content detection coverage and so mostly relies on the filename to determine the content. In this case monitor gives Chroma no information and thus is not highlighted.

If you'd like to add content detection for Node it would look something like this from the Go lexer.

alecthomas avatar Apr 14 '21 05:04 alecthomas