linux中Jekyll Pygments文法高亮安裝配置

來源:互聯網
上載者:User

安裝:

archlinux:

$ sudo pacman -S python2-pygments

或者通過pip安裝:

$ pip install pygments --user

我用的是ubuntu安裝的,命令是:

sudo apt-get install python-pygments

配置:

在Jekyll的配置文章_config.yml中開啟Pygments

pygments: true
mardown: redcarpet

一般都是這樣配置,不過新版本需要將pygments: true替換為highlighter: pygments

配置好後,我們去產生css檔案

輸入:

pygmentize -S default -f html > /root/Desktop/pygments.css

記住填寫你自己要產生到哪的路徑

產生後,將樣式加到網站中,然後進行調用,代碼如下:

<link rel="stylesheet" href="/css/pygments.css">

將這段代碼插入到_includes/header.html中調用

pygments.css需要放到你Jekyll的css目錄

使用:

高亮的代碼必須放在標籤{% highlight language %}和{% endhighlight %}之間,其中的language為你高亮的語言。

例子:

{% highlight python %}
#use jekyll pygments
#include <stdio.h>
jy = 'Jekyll'
print 'Use to %s' %(jy)
{% endhighlight %}

產生到文章的結果是

#use Jekyll
jy = 'Jekyll'
print 'Use to %s' %(jy)

Pygments的樣式

預設樣式為monokai、manni、rrt、perldoc、borland、colorful、default等等。

個人還是喜歡預設的default這個樣式。

你可以用python命令列出Pygments當前支援的樣式:

>>> from pygments.styles import STYLE_MAP
>>> STYLE_MAP.keys()
['monokai', 'manni', 'rrt', 'perldoc', 'borland', 'colorful', 'default', 'murphy', 'vs',
'trac', 'tango', 'fruity', 'autumn', 'bw', 'emacs', 'vim', 'pastie', 'friendly', 'native']

樣式的圖我就不截取了,自己找找吧,我覺得預設的default比較好。

如果找到喜歡的樣式,就可以上傳該樣式的css檔案,命令如下:

$ pygmentize -S 樣式名 -f html > your/path/pygments.css

基本就這樣了,不會排版,湊合這看下吧!!!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.