lib.directives.code¶
Pygments docutils directive.
The Pygments reStructuredText directive ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
This fragment is a Docutils 0.5 directive that renders source code (to HTML only, currently) via Pygments.
To use it, adjust the options below and copy the code into a module
that you import on initialization. The code then automatically
registers a sourcecode directive that you can use instead of
normal code blocks like this:
.. sourcecode:: python
My code goes here.
If you want to have different code styles, e.g. one with line numbers
and one without, add formatters with their names in the VARIANTS dict
below. You can invoke them instead of the DEFAULT one by using a
directive option:
.. sourcecode:: python
:linenos:
My code goes here.
Look at the directive documentation to get all the gory details.
- copyright:
Copyright 2006-2015 by the Pygments team, see AUTHORS.
- license:
BSD, see LICENSE for details.
-
django_docutils.lib.directives.code.patch_bash_session_lexer()¶
Monkey patch Bash Session lexer to gobble up initial space after prompt.
- Return type:
-
django_docutils.lib.directives.code.INLINESTYLES = False¶
Set to True if you want inline CSS styles instead of classes
-
django_docutils.lib.directives.code.DEFAULT = <pygments.formatters.html.HtmlFormatter object>¶
The default formatter
Add name -> formatter pairs for every variant you want to use
-
class django_docutils.lib.directives.code.CodeBlock¶
Bases:
DirectiveSource code syntax highlighting.
-
django_docutils.lib.directives.code.register_pygments_directive(directive='code-block')¶
Register pygments directive.
Examples
If you wish to use (override) code-block (default), that means:
.. code-block:: // will be highlighted by pygments