API Reference

See also




Register pygments directive.

Parameters:directive (str) – directive name to register pygments to.


If you wish to use (override) code-block (default), that means:

.. code-block::

    // will be highlighted by pygments
django_docutils.directives.DEFAULT = <pygments.formatters.html.HtmlFormatter object>

The default formatter

django_docutils.directives.VARIANTS = {}

Add name -> formatter pairs for every variant you want to use

Code block

class django_docutils.directives.CodeBlock(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)

Bases: docutils.parsers.rst.Directive

Source code syntax hightlighting.


Append self.options[‘name’] to node[‘names’] if it exists.

Also normalize the name string and register it as explicit target.


Throw an ERROR-level DirectiveError if the directive doesn’t have contents.

directive_error(level, message)

Return a DirectiveError suitable for being thrown as an exception.

Call “raise self.directive_error(level, message)” from within a directive implementation to return one single system message at level level, which automatically gets the directive block and the line number added.

Preferably use the debug, info, warning, error, or severe wrapper methods, e.g. self.error(message) to generate an ERROR-level directive error.


exception django_docutils.exc.BasedException