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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With