Github : override language definitions

11 Mar 2024

Recently, when I pushed some gren-lang code to GitHub, it was missing the syntax highlighting. Since GitHub recognises ELM and the same can be used for Gren, I was looking for ways to override the language definition on GitHub.

That led me to the github-linguist/linguist, the library GitHub uses to detect the languages. Using the override strategies, I was able to get the syntax highlighting for .gren files.

Using .gitattributes file

I added the .gitattributes file with the below content in the project root, and GitHub started showing Elm syntax highlighting for all the .gren files in the repository.

*.gren linguist-language=Elm

Another use case can be to syntax highlight for JSON with comments file

.vscode/*.json linguist-language=JSON-with-Comments

Below image shows the difference between before and after overriding the language definition of JSON with comments files.

JSON with Comments

If you find my work helpful, You can buy me a coffee.