Domanda

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

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top