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()[source]¶
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
- django_docutils.lib.directives.code.VARIANTS: Dict[str, Formatter[str]] = {}¶
Add name -> formatter pairs for every variant you want to use
- class django_docutils.lib.directives.code.CodeBlock(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶
Bases:
Directive
Source code syntax highlighting.
- required_arguments = 1¶
Number of required directive arguments.
- optional_arguments = 0¶
Number of optional arguments after the required arguments.
- final_argument_whitespace = True¶
May the final argument contain whitespace?
- option_spec = {}¶
Mapping of option names to validator functions.
- has_content = True¶
May the directive have content?