Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using syntax highlight from GitHub

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?

like image 226
Seb Nilsson Avatar asked Jun 05 '11 22:06

Seb Nilsson


People also ask

What does GitHub use for syntax highlighting?

We use Linguist to perform language detection and to select third-party grammars for syntax highlighting. You can find out which keywords are valid in the languages YAML file.

How do I highlight in GitHub?

To link to multiple lines of highlighted code, select your first line of code and then CTRL+SHIFT click on the last line of code you want to highlight. Notice the URL is now appended with a range of line numbers (e.g. https://github.com/…/functions.php#L117-L148).

How do I highlight a Markdown in GitHub?

You can also create a Markdown hyperlink by highlighting the text and using the keyboard shortcut Command + V .


2 Answers

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.

like image 131
Stephen Diehl Avatar answered Sep 28 '22 19:09

Stephen Diehl


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.

like image 27
Rory O'Kane Avatar answered Sep 28 '22 19:09

Rory O'Kane