How to implement highlight in Jekyll 3.0?
Contents
Why do we need change?
On February 2, 2016, Github posted an article about an update in Github Page. Basically, it will run Jekyll 3.0 in Github Page, and the major impact are below:
- GitHub Pages will only support kramdown, Jekyll’s default Markdown engine.
- GitHub Pages now only supports Rouge.
- Local builds are significantly faster.
If you are building your website under Github Page, or even use Jekyll 3.0 to build directly, the main problem is that the old highlight function is no long workable. This post is gonna talk about how to use Rouge highlight under Jekyll 3.0.
Configuration setting
First of all, change some settings in your _config.yml
. markdown
will use kramdown
, highlighter
will use rouge
, also change syntax_highlighter
to rouge
. Below is the code:
1 | highlighter: rouge |
Use Rouge Highlight
Install rouge first locally, and change to whichever style you like.
Install Rouge
1 | $ gem install rouge |
Rouge style
1 | $ rougify help style |
You can find many avaiable themes, choose whichever you like. I would like to use monokai.sublime
as an example.1
$ rougify style monokai.sublime > assets/css/syntax.css
It will generate a css
file, link this css
file into html, and highlight will be avaiable in your website.1
<link href="/assets/css/syntax.css" rel="stylesheet">
Change Background Color
If you prefer to use black as your code block background color, you should add the following code into css
file.1
pre[class='highlight'] {background-color:#000000;}
Reference
This is the end of post