API Reference

See also

quickstart.

Directives

django_docutils.directives.register_pygments_directive(directive='code-block')

Register pygments directive.

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

Examples

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.

add_name(node)

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

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

assert_has_content()

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.

Exceptions

exception django_docutils.exc.BasedException