class Directive(object): (source)
Known subclasses: docutils.parsers.rst.directives.admonitions.BaseAdmonition
, docutils.parsers.rst.directives.body.BasePseudoSection
, docutils.parsers.rst.directives.body.BlockQuote
, docutils.parsers.rst.directives.body.CodeBlock
, docutils.parsers.rst.directives.body.Compound
, docutils.parsers.rst.directives.body.Container
, docutils.parsers.rst.directives.body.LineBlock
, docutils.parsers.rst.directives.body.MathBlock
, docutils.parsers.rst.directives.body.ParsedLiteral
, docutils.parsers.rst.directives.body.Rubric
, docutils.parsers.rst.directives.html.Meta
, docutils.parsers.rst.directives.images.Image
, docutils.parsers.rst.directives.misc.Class
, docutils.parsers.rst.directives.misc.Date
, docutils.parsers.rst.directives.misc.DefaultRole
, docutils.parsers.rst.directives.misc.Include
, docutils.parsers.rst.directives.misc.Raw
, docutils.parsers.rst.directives.misc.Replace
, docutils.parsers.rst.directives.misc.Role
, docutils.parsers.rst.directives.misc.TestDirective
, docutils.parsers.rst.directives.misc.Title
, docutils.parsers.rst.directives.misc.Unicode
, docutils.parsers.rst.directives.parts.Contents
, docutils.parsers.rst.directives.parts.Footer
, docutils.parsers.rst.directives.parts.Header
, docutils.parsers.rst.directives.parts.Sectnum
, docutils.parsers.rst.directives.references.TargetNotes
, docutils.parsers.rst.directives.tables.Table
Base class for reStructuredText directives.
The following attributes may be set by subclasses. They are interpreted by the directive parser (which runs the directive class):
required_arguments
: The number of required arguments (default:
0).
optional_arguments
: The number of optional arguments (default:
0).
final_argument_whitespace
: A boolean, indicating if the final
argument may contain whitespace (default: False).
option_spec
: A dictionary, mapping known option names to
conversion functions such as int
or float
(default: {}, no
options). Several conversion functions are defined in the
directives/__init__.py module.
Option conversion functions take a single parameter, the option
argument (a string or None), validate it and/or convert it
to the appropriate form. Conversion functions may raise
ValueError
and TypeError
exceptions.
has_content
: A boolean; True if content is allowed. Client
code must handle the case where content is required but not
supplied (an empty content list will be supplied).
Arguments are normally single whitespace-separated words. The
final argument may contain whitespace and/or newlines if
final_argument_whitespace
is True.
If the form of the arguments is more complex, specify only one
argument (either required or optional) and set
final_argument_whitespace
to True; the client code must do any
context-sensitive parsing.
When a directive implementation is being run, the directive class
is instantiated, and the run()
method is executed. During
instantiation, the following instance variables are set:
option_spec
above).Directive functions return a list of nodes which will be inserted into the document tree at the point where the directive was encountered. This can be an empty list if there is nothing to insert.
For ordinary directives, the list must contain body elements or
structural elements. Some directives are intended specifically
for substitution definitions, and must return a list of Text
nodes and/or inline elements (suitable for inline insertion, in
place of the substitution reference). Such directives must verify
substitution definition context, typically using code like this:
if not isinstance(state, states.SubstitutionDef): error = state_machine.reporter.error( 'Invalid context: the "%s" directive can only be used ' 'within a substitution definition.' % (name), nodes.literal_block(block_text, block_text), line=lineno) return [error]
Method | __init__ |
Undocumented |
Method | add_name |
Append self.options['name'] to node['names'] if it exists. |
Method | assert_has_content |
Throw an ERROR-level DirectiveError if the directive doesn't have contents. |
Method | debug |
Undocumented |
Method | directive_error |
Return a DirectiveError suitable for being thrown as an exception. |
Method | error |
Undocumented |
Method | info |
Undocumented |
Method | run |
Undocumented |
Method | severe |
Undocumented |
Method | warning |
Undocumented |
Class Variable | final_argument_whitespace |
May the final argument contain whitespace? |
Class Variable | has_content |
May the directive have content? |
Class Variable | option_spec |
Mapping of option names to validator functions. |
Class Variable | optional_arguments |
Number of optional arguments after the required arguments. |
Class Variable | required_arguments |
Number of required directive arguments. |
Instance Variable | arguments |
Undocumented |
Instance Variable | block_text |
Undocumented |
Instance Variable | content |
Undocumented |
Instance Variable | content_offset |
Undocumented |
Instance Variable | lineno |
Undocumented |
Instance Variable | name |
Undocumented |
Instance Variable | options |
Undocumented |
Instance Variable | state |
Undocumented |
Instance Variable | state_machine |
Undocumented |
Undocumented
Append self.options['name'] to node['names'] if it exists.
Also normalize the name string and register it as explicit target.
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.
docutils.parsers.rst.directives.admonitions.BaseAdmonition
, docutils.parsers.rst.directives.body.BasePseudoSection
, docutils.parsers.rst.directives.body.BlockQuote
, docutils.parsers.rst.directives.body.CodeBlock
, docutils.parsers.rst.directives.body.Compound
, docutils.parsers.rst.directives.body.Container
, docutils.parsers.rst.directives.body.LineBlock
, docutils.parsers.rst.directives.body.MathBlock
, docutils.parsers.rst.directives.body.ParsedLiteral
, docutils.parsers.rst.directives.body.Rubric
, docutils.parsers.rst.directives.html.Meta
, docutils.parsers.rst.directives.images.Image
, docutils.parsers.rst.directives.misc.Class
, docutils.parsers.rst.directives.misc.Date
, docutils.parsers.rst.directives.misc.DefaultRole
, docutils.parsers.rst.directives.misc.Include
, docutils.parsers.rst.directives.misc.Raw
, docutils.parsers.rst.directives.misc.Replace
, docutils.parsers.rst.directives.misc.Role
, docutils.parsers.rst.directives.misc.TestDirective
, docutils.parsers.rst.directives.misc.Title
, docutils.parsers.rst.directives.misc.Unicode
, docutils.parsers.rst.directives.parts.Contents
, docutils.parsers.rst.directives.parts.Footer
, docutils.parsers.rst.directives.parts.Header
, docutils.parsers.rst.directives.parts.Sectnum
, docutils.parsers.rst.directives.references.TargetNotes
, docutils.parsers.rst.directives.tables.CSVTable
, docutils.parsers.rst.directives.tables.ListTable
, docutils.parsers.rst.directives.tables.RSTTable
Undocumented
docutils.parsers.rst.directives.admonitions.BaseAdmonition
, docutils.parsers.rst.directives.body.BasePseudoSection
, docutils.parsers.rst.directives.body.Container
, docutils.parsers.rst.directives.body.Rubric
, docutils.parsers.rst.directives.images.Image
, docutils.parsers.rst.directives.misc.Class
, docutils.parsers.rst.directives.misc.DefaultRole
, docutils.parsers.rst.directives.misc.Include
, docutils.parsers.rst.directives.misc.Raw
, docutils.parsers.rst.directives.misc.TestDirective
, docutils.parsers.rst.directives.misc.Title
, docutils.parsers.rst.directives.misc.Unicode
, docutils.parsers.rst.directives.parts.Contents
, docutils.parsers.rst.directives.tables.Table
docutils.parsers.rst.directives.admonitions.BaseAdmonition
, docutils.parsers.rst.directives.body.BasePseudoSection
, docutils.parsers.rst.directives.body.BlockQuote
, docutils.parsers.rst.directives.body.CodeBlock
, docutils.parsers.rst.directives.body.Compound
, docutils.parsers.rst.directives.body.Container
, docutils.parsers.rst.directives.body.LineBlock
, docutils.parsers.rst.directives.body.MathBlock
, docutils.parsers.rst.directives.body.ParsedLiteral
, docutils.parsers.rst.directives.html.Meta
, docutils.parsers.rst.directives.images.Figure
, docutils.parsers.rst.directives.misc.Class
, docutils.parsers.rst.directives.misc.Date
, docutils.parsers.rst.directives.misc.Raw
, docutils.parsers.rst.directives.misc.Replace
, docutils.parsers.rst.directives.misc.Role
, docutils.parsers.rst.directives.misc.TestDirective
, docutils.parsers.rst.directives.parts.Footer
, docutils.parsers.rst.directives.parts.Header
, docutils.parsers.rst.directives.tables.Table
docutils.parsers.rst.directives.admonitions.BaseAdmonition
, docutils.parsers.rst.directives.body.BasePseudoSection
, docutils.parsers.rst.directives.body.CodeBlock
, docutils.parsers.rst.directives.body.Compound
, docutils.parsers.rst.directives.body.Container
, docutils.parsers.rst.directives.body.LineBlock
, docutils.parsers.rst.directives.body.MathBlock
, docutils.parsers.rst.directives.body.ParsedLiteral
, docutils.parsers.rst.directives.body.Rubric
, docutils.parsers.rst.directives.images.Image
, docutils.parsers.rst.directives.misc.Include
, docutils.parsers.rst.directives.misc.Raw
, docutils.parsers.rst.directives.misc.TestDirective
, docutils.parsers.rst.directives.misc.Unicode
, docutils.parsers.rst.directives.parts.Contents
, docutils.parsers.rst.directives.parts.Sectnum
, docutils.parsers.rst.directives.references.TargetNotes
, docutils.parsers.rst.directives.tables.Table
docutils.parsers.rst.directives.body.BasePseudoSection
, docutils.parsers.rst.directives.body.CodeBlock
, docutils.parsers.rst.directives.body.Container
, docutils.parsers.rst.directives.body.Rubric
, docutils.parsers.rst.directives.images.Image
, docutils.parsers.rst.directives.misc.Class
, docutils.parsers.rst.directives.misc.DefaultRole
, docutils.parsers.rst.directives.misc.Include
, docutils.parsers.rst.directives.misc.Raw
, docutils.parsers.rst.directives.misc.TestDirective
, docutils.parsers.rst.directives.misc.Title
, docutils.parsers.rst.directives.misc.Unicode
, docutils.parsers.rst.directives.parts.Contents
, docutils.parsers.rst.directives.tables.Table
docutils.parsers.rst.directives.admonitions.Admonition
, docutils.parsers.rst.directives.body.BasePseudoSection
, docutils.parsers.rst.directives.body.Rubric
, docutils.parsers.rst.directives.images.Image
, docutils.parsers.rst.directives.misc.Class
, docutils.parsers.rst.directives.misc.Include
, docutils.parsers.rst.directives.misc.Raw
, docutils.parsers.rst.directives.misc.Title
, docutils.parsers.rst.directives.misc.Unicode