As I stated in my comment, Github uses Linguist to provide syntax highlighting. On Github, you can use this to specify syntax highlighting like so:
```ruby
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
```
Unfortunately, there's no good way to convert Markdown directly to a PDF file with syntax highlighting.
Alternatives:
Vim:
If you have vim, you can easily achieve syntax highlighting by running the following from a terminal:
vim -c hardcopy -c quit /path/to/file.ps
Or inside of vim:
:hardcopy >/path/to/file.ps
This will produce a PostScript file that can be converted to pdf using, for example, ps2pdf:
ps2pdf /path/to/file.ps
Source-highlight:
If you'd like instead to go the route of HTML or LaTeX, you could try Source-highlight instead. A list of all languages supported by Source-highlight can be found here.
A few example Source-highlight commands include:
source-highlight -s java -f html -i Hello.java -o Hello1.html
source-highlight -s java -f html --input Hello.java --output Hello2.html --doc
source-highlight -s java -f html -i Hello.java -o Hello3.html --title "Happy Java with java2html :-)" --tab 3
Using this input file
And each outputting their own respective HTML file:
Hello1.html
Hello2.html
Hello3.html
Further examples of Source-highlight usage can be found here
Windows:
Vim, ps2pdf (provided by Ghostscript) and Source-highlight are all available via Cygwin.
@dillmo, Convert to HTML first, then use Chrome to print-to-pdf.
– Pacerier – 2016-02-18T20:30:15.450The syntax coloring on GitHub is not part of GitHub Flavored Markdown. At least as far as I know. – Der Hochstapler – 2013-12-16T12:51:48.513
@OliverSalzburg Github uses Linguist to provide syntax highlighting.
– DanteTheEgregore – 2013-12-16T13:37:52.253