Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jekyll not highlighting with rouge highlighter

Tags:

jekyll

My Jekyll blog (Github pages) seems not to highlight the syntax properly, both locally hosted and hosted on Github. My _config.yml looks as follows

#Others
markdown: kramdown

# Syntax highlighting
highlighter: rouge
kramdown:
    input: GFM 
    syntax_highlighter: rouge

And in one post I tried fencing a code block with the python tag like this

```python
import urllib2
from bs4 import BeautifulSoup
html = urllib2.urlopen( "http://www.google.com" ).read()
soup = BeautifulSoup(html)
```

But this renders the page without highlights link. Code is on Github available here. Jekyll version on my system is 3.1.1.

like image 759
Rainymood Avatar asked Jun 12 '16 06:06

Rainymood


1 Answers

There is three ways to write code snippets in jekyll :

1 - jekyll highlight

{% highlight python %}
import urllib2
[...]
{% endhighlight %}

2 - fenced code block

```python
import urllib2
[...]
```
~~~python
import urllib2
[...]
~~~

3 - markdown four space indentation

    import urllib2
    [...]

Only first and second can produce code highlight with rouge. The third, the one that you actually use, only surround your code with tag, but rouge or any highlighter you set, will not be used by kramdown.

So, you can switch to first or second solution.

Another thing, if you want to "color your code", you need an highlight css. You can search for pygment style sheets.

like image 133
David Jacquel Avatar answered Oct 03 '22 20:10

David Jacquel