Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does one of my code previews on GitHub look like plain text?

Tags:

github

matlab

A recent commit to my repository makes the code for one of the .m files look like regular plain text (snippet image below) – no colored keywords or anything. The other .m files previews look normal though. I can't see any noticeable difference between the file with the non colored preview and the other ones. This is kind of inconvenient as scanning the code preview on GitHub is less efficient without the colors. I tried making pushing again and it's the same. Is there a way to fix this?

enter image description here

like image 298
Brian Barry Avatar asked Oct 16 '20 19:10

Brian Barry


People also ask

How do I view the GitHub code in my browser?

Go to any GitHub repository and then press the dot key on your keyboard. Visual Studio Code will appear in your browser. It will load your entire repository and you can open any file from it. You have your entire source code with syntax highlighting and coloring.

What is GitHub permalink?

Press Y to permalink to a file in a specific commit This will permanently link to the exact version of the file in that commit. For example: https://github.com/github/codeql/blob/b212af08a6cffbb434f3c8a2795a579e092792fd/README.md.


1 Answers

This is most likely caused by linguist (the software used on GitHub to guess the code's language to use for highlighting) miss-guessing the language for this file.

The .m extension is used by various other languages besides MATLAB (Mathematica and ObjectiveC, I believe). If linguist guesses wrong, then the highlighting used is wrong.

To tell GitHub what language your code is, add a .gitattributes file to the root of your repository, and in this file add a line like this:

src/*.m linguist-language=matlab

(replace src/*.m with whatever you need to match the names of your MATLAB M-files).

like image 199
Cris Luengo Avatar answered Oct 04 '22 20:10

Cris Luengo