2
votes

How to highlight fenced code block in Jekyll using Pygments?

```c
for(int i = 0; i < n; i++){
   ...
}
```

doesn't work. I have to write like this:

{% highlight c %}
for(int i = 0; i < n; i++){
   ...
}
{% endhighlight %}

I don't like to use Liquid tags and I am using Kramdown.
I am not ready to switch from Kramdown to Redcarpet. Rouge works fine with fenced code block but I want to use Pygments because it supports more programming languages.
This problem is similar to mine except that it's too old.

1

1 Answers

0
votes

Jekyll doesn't understand fenced code block out of the box. This can be easily resolved with the Github Flavored Markdown (aka GFM) parameter (see documentation).

In _config.yml, set :

kramdown:
  input: GFM

But : Jekyll 3.x default highlighter is now rouge, that does code highlight for a lot of languages and doesn't need python install.