Syntax highlighting on GitHub's Wiki: Specifying the programming language
Asked Answered
E

3

19

GitHub uses something known as the "GitHub Flavored Markdown" for messages, issues and comments. My questions are:

  • Does GitHub also use this syntax for their Wiki?
  • From what I understand one can specify the programming language for syntax highlighting using the following syntax:

    ```ruby  
    require 'redcarpet'  
    markdown = Redcarpet.new("Hello World!")  
    puts markdown.to_html  
    ```
    

    Where one can specify the programming language after the ``` string (e.g. ```ruby)

    My question is: How do I look up the specifier for a programming language? (e.g. C does not seem to work for the C programming language)

Extramundane answered 19/7, 2012 at 19:40 Comment(1)
Both C and c should work.Marxismleninism
C
10

For a list of the possible lexers that github wiki can use see here: http://pygments.org/docs/lexers/

If you find that a certain lexer is not supported, github recommends forking their code and submitting it via a pull request: https://github.com/blog/774-git-powered-wikis-improved

Capacitance answered 19/7, 2012 at 20:3 Comment(1)
GitHub used Pygments for syntax highlighting at a time, but the list of lexers from Pygments never fully matched the list of available lexers in GitHub. GitHub now relies on Sublime Text, Atom, and TextMate grammars for syntax highlighting. See 3D1T0R's answer for the list of lexers available.Marxismleninism
U
6

Quoting GitHub's documentation on the subject:

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

Linguist's "Grammar index" may prove also useful.

Uhland answered 14/7, 2017 at 21:8 Comment(0)
M
2

How do I look up the specifier for a programming language?

The up-to-date list of language specifiers can be deduced from the main configuration file of the Linguist repository, languages.yml. For each language in that list, you can use as specifiers:

  1. The language name
  2. Any of the language aliases
  3. Any of the file extensions, with or without a leading ..

White spaces must be replaced by dashes (e.g., emacs-lisp is one specifier for Emacs Lisp). Languages with a tm_scope: none entry don't have a grammar defined and won't be highlighted on github.com.

jmm made this reverse engineering effort and received confirmation from one of GitHub's engineers. He opened an issue with all the information on Linguist and maintains a wiki page with the specifiers for all languages (which might not be up-to-date).

Does GitHub also use this syntax for their Wiki?

Yes, but github.com's wikis also supports several other formats. You can find the complete list on the markup repository.

Marxismleninism answered 20/8, 2017 at 19:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.