How to install Pygments Restructured text directive?
Download
Go and download the file rst-directive.py. Then install Docutils and Pygments:
easy_install docutils pygments
Installation
Copy the rst-directive.py file to python2.5/site-packages/docutils-xxx/parsers/rst/directives. Edit the just copied file and set INLINESTYLES to True if you want inline CSS styles or False if you want classes. If you choose the latter, make sure you include a CSS file with all styles. This file can be generated using the following code:
pygmentize -S colorful -f html > highlighting.css
Edit the file __init__.py in the same directory and add the pygments directive:
_directive_registry = {
'sourcecode': ('rst-directive', 'pygments_directive'),
'attention': ('admonitions', 'attention'),
...
Now you can use the sourcecode directive in any reST-document as follows:
.. sourcecode:: python :linenos: print "Hello World!"
Note: The Pygments-directive only supports HTML-output at the moment.
The :linenos: option shows linenumbers in your sourcecode. To enable this, uncomment the following line in rst-directive.py:
VARIANTS = {
'linenos': HtmlFormatter(noclasses=INLINESTYLES, linenos=True),
}
