Home » Html » Using syntax highlight from GitHub

Using syntax highlight from GitHub

Posted by: admin November 29, 2017 Leave a comment


What syntax highlighting is used on GitHub (for HTML, CSS, JavaScript, C#) when viewing source code-file and is it available for the public to use?

It works on the page and it works when embedding on a page (from a Gist), like this:

<script src="https://gist.github.com/1009439.js"></script>

But can I just include their JavaScript-library and let it highlight my code?


Github uses pygments to highlight syntax. Pygments is running on the server, instead of a pure Javascript client solution. If you’re looking for a Javascript solution check out this review of the various options.


According to this help page, GitHub currently highlights syntax with the open-source Linguist library for Ruby. Linguist highlights each language using the tmLanguage files linked in vendor/grammars.

Since Linguist is written in Ruby, it can only be used on the server. If you want a client-side JavaScript library that you can just include on a page, you will have to find a different library.


According to this: http://www.infoq.com/news/2008/03/github-git-repository-hosting

they are using Python Pygments

Chris Wanstrath shared some
information about the inner workings
of GitHub with InfoQ:

GitHub is mostly implemented in Rails.
The post-commit integration mini-apps
we’re working on are all written in
Merb, we use the Python Pygments for
syntax highlighting, and we use Ara T.
Howard’s Bj plus some Ruby scripts for
our queueing system. And, of course,
we use the Ruby Grit library to
interface with Git.


I believe they use their albino gem. It is a Ruby wrapper for the pygments syntax highlighter.

Here is an article of a comparison I read recently on javascript based syntax highlighters (if that is what you need): http://softwaremaniacs.org/blog/2011/05/22/highlighters-comparison/


As others have said previously, GitHub uses Pygments. You can achieve the same effect by using it together with pygments-style-github.