reStructuredText and Markdown have directives that generate line numbers for code snippets. Install Pygments to use these directives.

Following examples will generate this output,

def example():
    print 'Hello World'


reStructuredText has code-block directive to insert code snippets in your markup. Use linenos flag to switch on line numbers for the snippet.

.. code-block:: python

    def example():
        print 'Hello World'


Python-Markdown uses CodeHilite extension for syntax highlighting. Setup CodeHilite, then use Shebang !# to generate line numbers.

def example():
    print 'Hello World'

Like this post? Share on: TwitterFacebookEmail

Talha Mansoor Avatar Talha Mansoor is the creator and lead developer of Elegant theme.

Keep Reading