문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top