matlabgithub

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


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


Solution

  • 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).