It seems like syntax highlighting in Jekyll is limited to using liquid tags and pygments like so:
{% highlight bash %}
cd ~
{% endhighlight %}
Fenced blocks were introduced with Redcarpet 2. Jekyll now supports Redcarpet 2.
As an aside I am using Redcarpet with Rouge until Kramdown support is available.
In addition some people prefer Nanoc to Jekyll.
So I ran into this problem as well and after banging my head around a lot of places finally realised with official redcarpet2 support in Jekyll this is pretty simple. Write this in your _config.yml
# Conversion
markdown: redcarpet
highlighter: pygments
redcarpet:
extensions: ["no_intra_emphasis", "fenced_code_blocks", "autolink", "strikethrough", "superscript"]
Make sure that you have pygments css file and it is included. THIS STEP IS IMPORTANT.
You can read my blog post http://blog.championswimmer.in/2015/10/jekyllsyntax-highlighting-in-github-favoured-markdown-codeblocks/ for details.
Step 1. Install Redcarpet.
gem install redcarpet
Step 2. Update the build settings in your _config.yaml
like this.
# Build settings
#markdown: kramdown
markdown: redcarpet
You can also use the triple-tilde syntax:
~~~ruby
class Base
def two
1 + 1
end
end
~~~
which is supported by Kramdown (Jekyll).
Redcarpet is integrated integrated into Jekyll by default and code highlighting will function as expected.
For older Jekyll blogs:
Install redcarpet gem:
gem install redcarpet
Update _config.yaml
markdown: redcarpet
For reference and further info see:
Closed Github Issue
Updated Jekyll Codebase
Markdown allows HTML, so if you don't mind adding a bit of JS, you could do this:
## A section
Here is some Ruby code.
<pre>
<code class="ruby">
puts "hello"
</code>
</pre>
Then you could use Highlight.js (documentation here) to add highlighting based on that class.
It's not an ideal solution, but it should work with any Markdown parser.