Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to support line number when using pygments with Jekyll

How can I number the code lines which are highlighted using pygments in Jekyll?

like image 854
Usman Ismail Avatar asked Jun 19 '12 01:06

Usman Ismail


1 Answers

According to the Liquid Extensions wiki page of the Jekyll documentation, the highlight Liquid tag has an optional second parameter, which may have the value linenos to turn on line numbering:

{% highlight language linenos %}
your code here
{% endhighlight %}

Use it with caution. With linenos the line numbers are actually inserted in the code's text, so will be impossible to copy the code block without them. (This could be solved by letting the visitor to $('.lineno').toggle() the line numbers' visibility. Works in Firefox, not sure if is portable.)

Update: Better use linenos=table:

{% highlight language linenos=table %}
your code here
{% endhighlight %}

That will place the code in a table with two cells: first td all the line numbers, second td the code itself. This makes possible to select only the code, without the line numbers.

like image 95
manatwork Avatar answered Nov 08 '22 08:11

manatwork