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

Following examples will generate this output,

1
2
def example():
    print 'Hello World'

reStructuredText

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
    :linenos:

    def example():
        print 'Hello World'

Markdown

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

#!python
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


Published

Last Updated

Category

Components

Tags

Stay in Touch

Get New Release Alert