Search code examples
githubmarkdown

Inline code syntax highlighting in GitHub markdown?


GitHub-flavored markdown supports syntax highlighting in codeblocks. This is done by adding the name of the language next to the triple-grave codeblock markers:

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

Standard markdown also supports inline codeblocks by wrapping text in `single graves`. Is there any way to add syntax highlighting to these inline codeblocks?


Solution

  • GitHub comments, wikis, README.md etc. use GFM, essentially CommonMark with some extensions, where it's not possible to add syntax highlighting. (Follow the link to see whether anything has changed, but don't hold your breath because nothing has in the last decade.)

    However, GitHub Pages uses Jekyll and by extension kramdown where you can use:

    `x = 4`{:.ruby}
    

    P.S. If you happen to use pandoc, the syntax is:

    `x = 4`{.ruby}