4

github automaticall syntax highlights any code files such as those with .c extensions. And there seems plenty of information about controlling highlighting from within 'markdown' or .md files.

But how can I get it to highlight code files that it doesn't know about?

I can't even get the tabbing right - if I say 4-spaces tabs while editing, it goes back to 8-space ones when I've finished.

I don't care what highlighting style it uses even if it's the wrong language; it must be better than the plain text appearance which looks really flat. Oddly, when editing it uses some sort of highlighting, which again disappears when I've finished.

The files aren't in any well-known language so the highlighting won't be perfect; I just want a bit of colour. But I'd rather not change file extensions as that could be confusing.

bartc
  • 304
  • 4
  • 9
  • Use IDE for syntax highlight, or GitHub desktop for Windows or for Mac. – Vy Do Oct 30 '16 at 09:31
  • I only use github so other people can see examples of my own languages. They just look drab without the highlighting and untidy with the wrong tabbing. (I develop using my own IDE, so it's not a problem for me.) – bartc Oct 30 '16 at 15:24
  • Feb. 2021: this is now available with the online GitHub editor! See my updated answer below. – VonC Feb 27 '21 at 21:45

1 Answers1

2

The tabbing is done through a ?t=4 parameter added to the GitHub url.

But the syntax highlighting (using Rouge on GitHub pages for instance) itself is either:


But how can I get it to highlight code files that it doesn't know about?

Update Feb. 2021 (5 years later)

Nat Friedman (CEO of GitHub) announces it on Twitter:

Another tiny but nice improvement we just shipped to GitHub – syntax highlighting now works on new files without the need to commit first.

Syntax Highlighting

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hard and fast information seems incredibly elusive with github but after more searching have found I can use 'vim: set filetype=' in my sources. Except that I will have to change my language to ignore 'vim:' lines! I just need to find the language that matches mine the best. The tabbing, I will need to suggest using the ?ts=4' trick. (What does the tab/spacing setting achieve in the editor if it's just ignored anyway after Commit?) – bartc Oct 30 '16 at 11:38