docutils.nodes module

Docutils document tree element class library.

Classes in CamelCase are abstract base classes or auxiliary classes. The one exception is Text, for a text (PCDATA) node; uppercase is used to differentiate from element classes. Classes in lower_case_with_underscores are element classes, matching the XML element generic identifiers in the DTD.

The position of each node (the level at which it can occur) is significant and is represented by abstract base classes (Root, Structural, Body, Inline, etc.). Certain transformations will be easier because we can use isinstance(node, base_class) to determine the position of the node in the hierarchy.

class Node[source]

Bases: object

Abstract base class of nodes in a document tree.

parent = None

Back-reference to the Node immediately containing this Node.

source = None

Path or description of the input source which generated this Node.

line = None

The line number (1-based) of the beginning of this Node in source.

_document = None
property document

Return the document root node of the tree containing this Node.

__bool__()[source]

Node instances are always true, even if they’re empty. A node is more than a simple container. Its boolean “truth” does not depend on having one or more subnodes in the doctree.

Use len() to check node length.

asdom(dom=None)[source]

Return a DOM fragment representation of this Node.

pformat(indent='    ', level=0)[source]

Return an indented pseudo-XML representation, for test purposes.

Override in subclasses.

copy()[source]

Return a copy of self.

deepcopy()[source]

Return a deep copy of self (also copying children).

astext()[source]

Return a string representation of this Node.

setup_child(child)[source]
walk(visitor)[source]

Traverse a tree of Node objects, calling the dispatch_visit() method of visitor when entering each node. (The walkabout() method is similar, except it also calls the dispatch_departure() method before exiting each node.)

This tree traversal supports limited in-place tree modifications. Replacing one node with one or more nodes is OK, as is removing an element. However, if the node removed or replaced occurs after the current node, the old node will still be traversed, and any new nodes will not.

Within visit methods (and depart methods for walkabout()), TreePruningException subclasses may be raised (SkipChildren, SkipSiblings, SkipNode, SkipDeparture).

Parameter visitor: A NodeVisitor object, containing a visit implementation for each Node subclass encountered.

Return true if we should stop the traversal.

walkabout(visitor)[source]

Perform a tree traversal similarly to Node.walk() (which see), except also call the dispatch_departure() method before exiting each node.

Parameter visitor: A NodeVisitor object, containing a visit and depart implementation for each Node subclass encountered.

Return true if we should stop the traversal.

_fast_findall(cls)[source]

Return iterator that only supports instance checks.

_superfast_findall()[source]

Return iterator that doesn’t check for a condition.

traverse(condition=None, include_self=True, descend=True, siblings=False, ascend=False)[source]

Return list of nodes following self.

For looping, Node.findall() is faster and more memory efficient.

findall(condition=None, include_self=True, descend=True, siblings=False, ascend=False)[source]

Return an iterator yielding nodes following self:

  • self (if include_self is true)

  • all descendants in tree traversal order (if descend is true)

  • the following siblings (if siblings is true) and their descendants (if also descend is true)

  • the following siblings of the parent (if ascend is true) and their descendants (if also descend is true), and so on.

If condition is not None, the iterator yields only nodes for which condition(node) is true. If condition is a node class cls, it is equivalent to a function consisting of return isinstance(node, cls).

If ascend is true, assume siblings to be true as well.

If the tree structure is modified during iteration, the result is undefined.

For example, given the following tree:

<paragraph>
    <emphasis>      <--- emphasis.traverse() and
        <strong>    <--- strong.traverse() are called.
            Foo
        Bar
    <reference name="Baz" refid="baz">
        Baz

Then tuple(emphasis.traverse()) equals

(<emphasis>, <strong>, <#text: Foo>, <#text: Bar>)

and list(strong.traverse(ascend=True) equals

[<strong>, <#text: Foo>, <#text: Bar>, <reference>, <#text: Baz>]
next_node(condition=None, include_self=False, descend=True, siblings=False, ascend=False)[source]

Return the first node in the iterator returned by findall(), or None if the iterable is empty.

Parameter list is the same as of traverse. Note that include_self defaults to False, though.

class reprunicode(s)[source]

Bases: str

Deprecated backwards compatibility stub. Use the standard str instead.

ensure_str(s)[source]

Deprecated backwards compatibility stub returning s.

unescape(text, restore_backslashes=False, respect_whitespace=False)[source]

Return a string with nulls removed or restored to backslashes. Backslash-escaped spaces are also removed.

class Text(data, rawsource=None)[source]

Bases: Node, str

Instances are terminal nodes (leaves) containing text only; no child nodes or attributes. Initialize by passing a string to the constructor.

Access the raw (null-escaped) text with str(<instance>) and unescaped text with <instance>.astext().

tagname = '#text'
children = ()

Text nodes have no children, and cannot have children.

static __new__(cls, data, rawsource=None)[source]

Assert that data is not an array of bytes and warn if the deprecated rawsource argument is used.

shortrepr(maxlen=18)[source]
_dom_node(domroot)[source]
astext()[source]

Return a string representation of this Node.

copy()[source]

Return a copy of self.

deepcopy()[source]

Return a deep copy of self (also copying children).

pformat(indent='    ', level=0)[source]

Return an indented pseudo-XML representation, for test purposes.

Override in subclasses.

rstrip(chars=None)[source]

Return a copy of the string with trailing whitespace removed.

If chars is given and not None, remove characters in chars instead.

lstrip(chars=None)[source]

Return a copy of the string with leading whitespace removed.

If chars is given and not None, remove characters in chars instead.

class Element(rawsource='', *children, **attributes)[source]

Bases: Node

Element is the superclass to all specific elements.

Elements contain attributes and child nodes. They can be described as a cross between a list and a dictionary.

Elements emulate dictionaries for external [1] attributes, indexing by attribute name (a string). To set the attribute ‘att’ to ‘value’, do:

element['att'] = 'value'

There are two special attributes: ‘ids’ and ‘names’. Both are lists of unique identifiers: ‘ids’ conform to the regular expression [a-z](-?[a-z0-9]+)* (see the make_id() function for rationale and details). ‘names’ serve as user-friendly interfaces to IDs; they are case- and whitespace-normalized (see the fully_normalize_name() function).

Elements emulate lists for child nodes (element nodes and/or text nodes), indexing by integer. To get the first child node, use:

element[0]

to iterate over the child nodes (without descending), use:

for child in element:
    ...

Elements may be constructed using the += operator. To add one new child node to element, do:

element += node

This is equivalent to element.append(node).

To add a list of multiple child nodes at once, use the same += operator:

element += [node1, node2]

This is equivalent to element.extend([node1, node2]).

basic_attributes = ('ids', 'classes', 'names', 'dupnames')

Tuple of attributes which are defined for every Element-derived class instance and can be safely transferred to a different node.

local_attributes = ('backrefs',)

Tuple of class-specific attributes that should not be copied with the standard attributes when replacing a node.

NOTE: Derived classes should override this value to prevent any of its attributes being copied by adding to the value in its parent class.

list_attributes = ('ids', 'classes', 'names', 'dupnames', 'backrefs')

Tuple of attributes that are automatically initialized to empty lists for all nodes.

known_attributes = ('ids', 'classes', 'names', 'dupnames', 'backrefs', 'source')

Tuple of attributes that are known to the Element base class.

child_text_separator = '\n\n'

Separator for child nodes, used by astext() method.

rawsource

The raw text from which this element was constructed.

NOTE: some elements do not set this value (default ‘’).

children

List of child nodes (elements and/or Text).

attributes

value}.

Type:

Dictionary of attribute {name

tagname = None

The element generic identifier. If None, it is set as an instance attribute to the name of the class.

_dom_node(domroot)[source]
shortrepr()[source]
starttag(quoteattr=None)[source]
endtag()[source]
emptytag()[source]
__iadd__(other)[source]

Append a node or a list of nodes to self.children.

astext()[source]

Return a string representation of this Node.

non_default_attributes()[source]
attlist()[source]
get(key, failobj=None)[source]
hasattr(attr)[source]
delattr(attr)[source]
setdefault(key, failobj=None)[source]
has_key(attr)
get_language_code(fallback='')[source]

Return node’s language tag.

Look iteratively in self and parents for a class argument starting with language- and return the remainder of it (which should be a BCP49 language tag) or the fallback.

append(item)[source]
extend(item)[source]
insert(index, item)[source]
pop(i=-1)[source]
remove(item)[source]
index(item, start=0, stop=9223372036854775807)[source]
previous_sibling()[source]

Return preceding sibling node or None.

is_not_default(key)[source]
update_basic_atts(dict_)[source]

Update basic attributes (‘ids’, ‘names’, ‘classes’, ‘dupnames’, but not ‘source’) from node or dictionary dict_.

append_attr_list(attr, values)[source]

For each element in values, if it does not exist in self[attr], append it.

NOTE: Requires self[attr] and values to be sequence type and the former should specifically be a list.

coerce_append_attr_list(attr, value)[source]

First, convert both self[attr] and value to a non-string sequence type; if either is not already a sequence, convert it to a list of one element. Then call append_attr_list.

NOTE: self[attr] and value both must not be None.

replace_attr(attr, value, force=True)[source]

If self[attr] does not exist or force is True or omitted, set self[attr] to value, otherwise do nothing.

copy_attr_convert(attr, value, replace=True)[source]

If attr is an attribute of self, set self[attr] to [self[attr], value], otherwise set self[attr] to value.

NOTE: replace is not used by this function and is kept only for

compatibility with the other copy functions.

copy_attr_coerce(attr, value, replace)[source]

If attr is an attribute of self and either self[attr] or value is a list, convert all non-sequence values to a sequence of 1 element and then concatenate the two sequence, setting the result to self[attr]. If both self[attr] and value are non-sequences and replace is True or self[attr] is None, replace self[attr] with value. Otherwise, do nothing.

copy_attr_concatenate(attr, value, replace)[source]

If attr is an attribute of self and both self[attr] and value are lists, concatenate the two sequences, setting the result to self[attr]. If either self[attr] or value are non-sequences and replace is True or self[attr] is None, replace self[attr] with value. Otherwise, do nothing.

copy_attr_consistent(attr, value, replace)[source]

If replace is True or self[attr] is None, replace self[attr] with value. Otherwise, do nothing.

update_all_atts(dict_, update_fun=<function Element.copy_attr_consistent>, replace=True, and_source=False)[source]

Updates all attributes from node or dictionary dict_.

Appends the basic attributes (‘ids’, ‘names’, ‘classes’, ‘dupnames’, but not ‘source’) and then, for all other attributes in dict_, updates the same attribute in self. When attributes with the same identifier appear in both self and dict_, the two values are merged based on the value of update_fun. Generally, when replace is True, the values in self are replaced or merged with the values in dict_; otherwise, the values in self may be preserved or merged. When and_source is True, the ‘source’ attribute is included in the copy.

NOTE: When replace is False, and self contains a ‘source’ attribute,

‘source’ is not replaced even when dict_ has a ‘source’ attribute, though it may still be merged into a list depending on the value of update_fun.

NOTE: It is easier to call the update-specific methods then to pass

the update_fun method to this function.

update_all_atts_consistantly(dict_, replace=True, and_source=False)[source]

Updates all attributes from node or dictionary dict_.

Appends the basic attributes (‘ids’, ‘names’, ‘classes’, ‘dupnames’, but not ‘source’) and then, for all other attributes in dict_, updates the same attribute in self. When attributes with the same identifier appear in both self and dict_ and replace is True, the values in self are replaced with the values in dict_; otherwise, the values in self are preserved. When and_source is True, the ‘source’ attribute is included in the copy.

NOTE: When replace is False, and self contains a ‘source’ attribute,

‘source’ is not replaced even when dict_ has a ‘source’ attribute, though it may still be merged into a list depending on the value of update_fun.

update_all_atts_concatenating(dict_, replace=True, and_source=False)[source]

Updates all attributes from node or dictionary dict_.

Appends the basic attributes (‘ids’, ‘names’, ‘classes’, ‘dupnames’, but not ‘source’) and then, for all other attributes in dict_, updates the same attribute in self. When attributes with the same identifier appear in both self and dict_ whose values aren’t each lists and replace is True, the values in self are replaced with the values in dict_; if the values from self and dict_ for the given identifier are both of list type, then the two lists are concatenated and the result stored in self; otherwise, the values in self are preserved. When and_source is True, the ‘source’ attribute is included in the copy.

NOTE: When replace is False, and self contains a ‘source’ attribute,

‘source’ is not replaced even when dict_ has a ‘source’ attribute, though it may still be merged into a list depending on the value of update_fun.

update_all_atts_coercion(dict_, replace=True, and_source=False)[source]

Updates all attributes from node or dictionary dict_.

Appends the basic attributes (‘ids’, ‘names’, ‘classes’, ‘dupnames’, but not ‘source’) and then, for all other attributes in dict_, updates the same attribute in self. When attributes with the same identifier appear in both self and dict_ whose values are both not lists and replace is True, the values in self are replaced with the values in dict_; if either of the values from self and dict_ for the given identifier are of list type, then first any non-lists are converted to 1-element lists and then the two lists are concatenated and the result stored in self; otherwise, the values in self are preserved. When and_source is True, the ‘source’ attribute is included in the copy.

NOTE: When replace is False, and self contains a ‘source’ attribute,

‘source’ is not replaced even when dict_ has a ‘source’ attribute, though it may still be merged into a list depending on the value of update_fun.

update_all_atts_convert(dict_, and_source=False)[source]

Updates all attributes from node or dictionary dict_.

Appends the basic attributes (‘ids’, ‘names’, ‘classes’, ‘dupnames’, but not ‘source’) and then, for all other attributes in dict_, updates the same attribute in self. When attributes with the same identifier appear in both self and dict_ then first any non-lists are converted to 1-element lists and then the two lists are concatenated and the result stored in self; otherwise, the values in self are preserved. When and_source is True, the ‘source’ attribute is included in the copy.

NOTE: When replace is False, and self contains a ‘source’ attribute,

‘source’ is not replaced even when dict_ has a ‘source’ attribute, though it may still be merged into a list depending on the value of update_fun.

clear()[source]
replace(old, new)[source]

Replace one child Node with another child or children.

replace_self(new)[source]

Replace self node with new, where new is a node or a list of nodes.

first_child_matching_class(childclass, start=0, end=9223372036854775807)[source]

Return the index of the first child whose class exactly matches.

Parameters:

  • childclass: A Node subclass to search for, or a tuple of Node classes. If a tuple, any of the classes may match.

  • start: Initial index to check.

  • end: Initial index to not check.

first_child_not_matching_class(childclass, start=0, end=9223372036854775807)[source]

Return the index of the first child whose class does not match.

Parameters:

  • childclass: A Node subclass to skip, or a tuple of Node classes. If a tuple, none of the classes may match.

  • start: Initial index to check.

  • end: Initial index to not check.

pformat(indent='    ', level=0)[source]

Return an indented pseudo-XML representation, for test purposes.

Override in subclasses.

copy() Element

Monkey-patch `nodes.Element.copy` to not copy the _document attribute.

xref: https://github.com/sphinx-doc/sphinx/issues/11116#issuecomment-1376767086

deepcopy() Element

Monkey-patch `nodes.Element.deepcopy` for speed.

set_class(name)[source]

Add a new class to the “classes” attribute.

note_referenced_by(name=None, id=None)[source]

Note that this Element has been referenced by its name name or id id.

classmethod is_not_list_attribute(attr)[source]

Returns True if and only if the given attribute is NOT one of the basic list attributes defined for all Elements.

classmethod is_not_known_attribute(attr)[source]

Returns True if and only if the given attribute is NOT recognized by this class.

class TextElement(rawsource='', text='', *children, **attributes)[source]

Bases: Element

An element which directly contains text.

Its children are all Text or Inline subclass nodes. You can check whether an element’s context is inline simply by checking whether its immediate parent is a TextElement instance (including subclasses). This is handy for nodes like image that can appear both inline and as standalone body elements.

If passing children to __init__(), make sure to set text to '' or some other suitable value.

child_text_separator = ''

Separator for child nodes, used by astext() method.

class FixedTextElement(rawsource='', text='', *children, **attributes)[source]

Bases: TextElement

An element which directly contains preformatted text.

class Resolvable[source]

Bases: object

resolved = 0
class BackLinkable[source]

Bases: object

add_backref(refid)[source]
class Root[source]

Bases: object

class Titular[source]

Bases: object

class PreBibliographic[source]

Bases: object

Category of Node which may occur before Bibliographic Nodes.

class Bibliographic[source]

Bases: object

class Decorative[source]

Bases: PreBibliographic

class Structural[source]

Bases: object

class Body[source]

Bases: object

class General[source]

Bases: Body

class Sequential[source]

Bases: Body

List-like elements.

class Admonition[source]

Bases: Body

class Special[source]

Bases: Body

Special internal body elements.

class Invisible[source]

Bases: PreBibliographic

Internal elements that don’t appear in output.

class Part[source]

Bases: object

class Inline[source]

Bases: object

class Referential[source]

Bases: Resolvable

class Targetable[source]

Bases: Resolvable

referenced = 0
indirect_reference_name = None

Holds the whitespace_normalized_name (contains mixed case) of a target. Required for MoinMoin/reST compatibility.

class Labeled[source]

Bases: object

Contains a label as its first element.

class document(settings, reporter, *args, **kwargs)[source]

Bases: Root, Structural, Element

The document root element.

Do not instantiate this class directly; use docutils.utils.new_document() instead.

current_source

Path to or description of the input source being processed.

current_line

Line number (1-based) of current_source.

settings

Runtime settings data record.

reporter

System message generator.

indirect_targets

List of indirect target nodes.

substitution_defs

Mapping of substitution names to substitution_definition nodes.

substitution_names

Mapping of case-normalized substitution names to case-sensitive names.

refnames

Mapping of names to lists of referencing nodes.

refids

Mapping of ids to lists of referencing nodes.

nameids

Mapping of names to unique id’s.

nametypes

True => explicit, False => implicit.

Type:

Mapping of names to hyperlink type (boolean

ids

Mapping of ids to nodes.

footnote_refs

Mapping of footnote labels to lists of footnote_reference nodes.

citation_refs

Mapping of citation labels to lists of citation_reference nodes.

autofootnotes

List of auto-numbered footnote nodes.

autofootnote_refs

List of auto-numbered footnote_reference nodes.

symbol_footnotes

List of symbol footnote nodes.

symbol_footnote_refs

List of symbol footnote_reference nodes.

footnotes

List of manually-numbered footnote nodes.

citations

List of citation nodes.

autofootnote_start

Initial auto-numbered footnote number.

symbol_footnote_start

Initial symbol footnote symbol index.

id_counter

Numbers added to otherwise identical IDs.

parse_messages

System messages generated while parsing.

transform_messages

System messages generated while applying transforms.

transformer

Storage for transforms to be applied to this document.

include_log

The current source’s parents (to detect inclusion loops).

decoration

Document’s decoration node.

__getstate__()[source]

Return dict with unpicklable references removed.

asdom(dom=None)[source]

Return a DOM representation of this document.

set_id(node, msgnode=None, suggested_prefix='')[source]
set_name_id_map(node, id, msgnode=None, explicit=None)[source]

self.nameids maps names to IDs, while self.nametypes maps names to booleans representing hyperlink type (True==explicit, False==implicit). This method updates the mappings.

The following state transition table shows how self.nameids items (“id”) and self.nametypes items (“type”) change with new input (a call to this method), and what actions are performed (“implicit”-type system messages are INFO/1, and “explicit”-type system messages are ERROR/3):

Old State

Input

Action

New State

Notes

id

type

new type

sys.msg.

dupname

id

type

explicit

new

True

implicit

new

False

False

explicit

new

True

old

False

explicit

implicit

old

new

True

True

explicit

explicit

new

True

old

True

explicit

explicit

new,old

True

[2]

False

implicit

implicit

new

False

old

False

implicit

implicit

new,old

False

True

implicit

implicit

new

True

old

True

implicit

implicit

new

old

True

set_duplicate_name_id(node, id, name, msgnode, explicit)[source]
has_name(name)[source]
note_implicit_target(target, msgnode=None)[source]
note_explicit_target(target, msgnode=None)[source]
note_refname(node)[source]
note_refid(node)[source]
note_indirect_target(target)[source]
note_anonymous_target(target)[source]
note_autofootnote(footnote)[source]
note_autofootnote_ref(ref)[source]
note_symbol_footnote(footnote)[source]
note_symbol_footnote_ref(ref)[source]
note_footnote(footnote)[source]
note_footnote_ref(ref)[source]
note_citation(citation)[source]
note_citation_ref(ref)[source]
note_substitution_def(subdef, def_name, msgnode=None)[source]
note_substitution_ref(subref, refname)[source]
note_pending(pending, priority=None)[source]
note_parse_message(message)[source]
note_transform_message(message)[source]
note_source(source, offset)[source]
copy()[source]

Monkey-patch `nodes.Element.copy` to not copy the _document attribute.

xref: https://github.com/sphinx-doc/sphinx/issues/11116#issuecomment-1376767086

get_decoration()[source]
class title(rawsource='', text='', *children, **attributes)[source]

Bases: Titular, PreBibliographic, TextElement

class subtitle(rawsource='', text='', *children, **attributes)[source]

Bases: Titular, PreBibliographic, TextElement

class rubric(rawsource='', text='', *children, **attributes)[source]

Bases: Titular, TextElement

class meta(rawsource='', *children, **attributes)[source]

Bases: PreBibliographic, Element

Container for “invisible” bibliographic data, or meta-data.

class docinfo(rawsource='', *children, **attributes)[source]

Bases: Bibliographic, Element

class author(rawsource='', text='', *children, **attributes)[source]

Bases: Bibliographic, TextElement

class authors(rawsource='', *children, **attributes)[source]

Bases: Bibliographic, Element

class organization(rawsource='', text='', *children, **attributes)[source]

Bases: Bibliographic, TextElement

class address(rawsource='', text='', *children, **attributes)[source]

Bases: Bibliographic, FixedTextElement

class contact(rawsource='', text='', *children, **attributes)[source]

Bases: Bibliographic, TextElement

class version(rawsource='', text='', *children, **attributes)[source]

Bases: Bibliographic, TextElement

class revision(rawsource='', text='', *children, **attributes)[source]

Bases: Bibliographic, TextElement

class status(rawsource='', text='', *children, **attributes)[source]

Bases: Bibliographic, TextElement

class date(rawsource='', text='', *children, **attributes)[source]

Bases: Bibliographic, TextElement

class copyright(rawsource='', text='', *children, **attributes)[source]

Bases: Bibliographic, TextElement

class decoration(rawsource='', *children, **attributes)[source]

Bases: Decorative, Element

get_header()[source]
class header(rawsource='', *children, **attributes)[source]

Bases: Decorative, Element

class footer(rawsource='', *children, **attributes)[source]

Bases: Decorative, Element

class section(rawsource='', *children, **attributes)[source]

Bases: Structural, Element

class topic(rawsource='', *children, **attributes)[source]

Bases: Structural, Element

Topics are terminal, “leaf” mini-sections, like block quotes with titles, or textual figures. A topic is just like a section, except that it has no subsections, and it doesn’t have to conform to section placement rules.

Topics are allowed wherever body elements (list, table, etc.) are allowed, but only at the top level of a section or document. Topics cannot nest inside topics, sidebars, or body elements; you can’t have a topic inside a table, list, block quote, etc.

class sidebar(rawsource='', *children, **attributes)[source]

Bases: Structural, Element

Sidebars are like miniature, parallel documents that occur inside other documents, providing related or reference material. A sidebar is typically offset by a border and “floats” to the side of the page; the document’s main text may flow around it. Sidebars can also be likened to super-footnotes; their content is outside of the flow of the document’s main text.

Sidebars are allowed wherever body elements (list, table, etc.) are allowed, but only at the top level of a section or document. Sidebars cannot nest inside sidebars, topics, or body elements; you can’t have a sidebar inside a table, list, block quote, etc.

class transition(rawsource='', *children, **attributes)[source]

Bases: Structural, Element

class paragraph(rawsource='', text='', *children, **attributes)[source]

Bases: General, TextElement

class compound(rawsource='', *children, **attributes)[source]

Bases: General, Element

class container(rawsource='', *children, **attributes)[source]

Bases: General, Element

class bullet_list(rawsource='', *children, **attributes)[source]

Bases: Sequential, Element

class enumerated_list(rawsource='', *children, **attributes)[source]

Bases: Sequential, Element

class list_item(rawsource='', *children, **attributes)[source]

Bases: Part, Element

class definition_list(rawsource='', *children, **attributes)[source]

Bases: Sequential, Element

class definition_list_item(rawsource='', *children, **attributes)[source]

Bases: Part, Element

class term(rawsource='', text='', *children, **attributes)[source]

Bases: Part, TextElement

class classifier(rawsource='', text='', *children, **attributes)[source]

Bases: Part, TextElement

class definition(rawsource='', *children, **attributes)[source]

Bases: Part, Element

class field_list(rawsource='', *children, **attributes)[source]

Bases: Sequential, Element

class field(rawsource='', *children, **attributes)[source]

Bases: Part, Element

class field_name(rawsource='', text='', *children, **attributes)[source]

Bases: Part, TextElement

class field_body(rawsource='', *children, **attributes)[source]

Bases: Part, Element

class option(rawsource='', *children, **attributes)[source]

Bases: Part, Element

child_text_separator = ''

Separator for child nodes, used by astext() method.

class option_argument(rawsource='', text='', *children, **attributes)[source]

Bases: Part, TextElement

astext()[source]

Return a string representation of this Node.

class option_group(rawsource='', *children, **attributes)[source]

Bases: Part, Element

child_text_separator = ', '

Separator for child nodes, used by astext() method.

class option_list(rawsource='', *children, **attributes)[source]

Bases: Sequential, Element

class option_list_item(rawsource='', *children, **attributes)[source]

Bases: Part, Element

child_text_separator = '  '

Separator for child nodes, used by astext() method.

class option_string(rawsource='', text='', *children, **attributes)[source]

Bases: Part, TextElement

class description(rawsource='', *children, **attributes)[source]

Bases: Part, Element

class literal_block(rawsource='', text='', *children, **attributes)[source]

Bases: General, FixedTextElement

class doctest_block(rawsource='', text='', *children, **attributes)[source]

Bases: General, FixedTextElement

class math_block(rawsource='', text='', *children, **attributes)[source]

Bases: General, FixedTextElement

class line_block(rawsource='', *children, **attributes)[source]

Bases: General, Element

class line(rawsource='', text='', *children, **attributes)[source]

Bases: Part, TextElement

indent = None
class block_quote(rawsource='', *children, **attributes)[source]

Bases: General, Element

class attribution(rawsource='', text='', *children, **attributes)[source]

Bases: Part, TextElement

class attention(rawsource='', *children, **attributes)[source]

Bases: Admonition, Element

class caution(rawsource='', *children, **attributes)[source]

Bases: Admonition, Element

class danger(rawsource='', *children, **attributes)[source]

Bases: Admonition, Element

class error(rawsource='', *children, **attributes)[source]

Bases: Admonition, Element

class important(rawsource='', *children, **attributes)[source]

Bases: Admonition, Element

class note(rawsource='', *children, **attributes)[source]

Bases: Admonition, Element

class tip(rawsource='', *children, **attributes)[source]

Bases: Admonition, Element

class hint(rawsource='', *children, **attributes)[source]

Bases: Admonition, Element

class warning(rawsource='', *children, **attributes)[source]

Bases: Admonition, Element

class admonition(rawsource='', *children, **attributes)[source]

Bases: Admonition, Element

class comment(rawsource='', text='', *children, **attributes)[source]

Bases: Special, Invisible, FixedTextElement

class substitution_definition(rawsource='', text='', *children, **attributes)[source]

Bases: Special, Invisible, TextElement

class target(rawsource='', text='', *children, **attributes)[source]

Bases: Special, Invisible, Inline, TextElement, Targetable

class footnote(rawsource='', *children, **attributes)[source]

Bases: General, BackLinkable, Element, Labeled, Targetable

class citation(rawsource='', *children, **attributes)[source]

Bases: General, BackLinkable, Element, Labeled, Targetable

class label(rawsource='', text='', *children, **attributes)[source]

Bases: Part, TextElement

class figure(rawsource='', *children, **attributes)[source]

Bases: General, Element

class caption(rawsource='', text='', *children, **attributes)[source]

Bases: Part, TextElement

class legend(rawsource='', *children, **attributes)[source]

Bases: Part, Element

class table(rawsource='', *children, **attributes)[source]

Bases: General, Element

class tgroup(rawsource='', *children, **attributes)[source]

Bases: Part, Element

class colspec(rawsource='', *children, **attributes)[source]

Bases: Part, Element

class thead(rawsource='', *children, **attributes)[source]

Bases: Part, Element

class tbody(rawsource='', *children, **attributes)[source]

Bases: Part, Element

class row(rawsource='', *children, **attributes)[source]

Bases: Part, Element

class entry(rawsource='', *children, **attributes)[source]

Bases: Part, Element

class system_message(message=None, *children, **attributes)[source]

Bases: Special, BackLinkable, PreBibliographic, Element

System message element.

Do not instantiate this class directly; use document.reporter.info/warning/error/severe() instead.

astext()[source]

Return a string representation of this Node.

class pending(transform, details=None, rawsource='', *children, **attributes)[source]

Bases: Special, Invisible, Element

The “pending” element is used to encapsulate a pending operation: the operation (transform), the point at which to apply it, and any data it requires. Only the pending operation’s location within the document is stored in the public document tree (by the “pending” object itself); the operation and its data are stored in the “pending” object’s internal instance attributes.

For example, say you want a table of contents in your reStructuredText document. The easiest way to specify where to put it is from within the document, with a directive:

.. contents::

But the “contents” directive can’t do its work until the entire document has been parsed and possibly transformed to some extent. So the directive code leaves a placeholder behind that will trigger the second phase of its processing, something like this:

<pending ...public attributes...> + internal attributes

Use document.note_pending() so that the docutils.transforms.Transformer stage of processing can run all pending transforms.

transform

The docutils.transforms.Transform class implementing the pending operation.

details

Detail data (dictionary) required by the pending operation.

pformat(indent='    ', level=0)[source]

Return an indented pseudo-XML representation, for test purposes.

Override in subclasses.

copy()[source]

Monkey-patch `nodes.Element.copy` to not copy the _document attribute.

xref: https://github.com/sphinx-doc/sphinx/issues/11116#issuecomment-1376767086

class raw(rawsource='', text='', *children, **attributes)[source]

Bases: Special, Inline, PreBibliographic, FixedTextElement

Raw data that is to be passed untouched to the Writer.

class emphasis(rawsource='', text='', *children, **attributes)[source]

Bases: Inline, TextElement

class strong(rawsource='', text='', *children, **attributes)[source]

Bases: Inline, TextElement

class literal(rawsource='', text='', *children, **attributes)[source]

Bases: Inline, TextElement

class reference(rawsource='', text='', *children, **attributes)[source]

Bases: General, Inline, Referential, TextElement

class footnote_reference(rawsource='', text='', *children, **attributes)[source]

Bases: Inline, Referential, TextElement

class citation_reference(rawsource='', text='', *children, **attributes)[source]

Bases: Inline, Referential, TextElement

class substitution_reference(rawsource='', text='', *children, **attributes)[source]

Bases: Inline, TextElement

class title_reference(rawsource='', text='', *children, **attributes)[source]

Bases: Inline, TextElement

class abbreviation(rawsource='', text='', *children, **attributes)[source]

Bases: Inline, TextElement

class acronym(rawsource='', text='', *children, **attributes)[source]

Bases: Inline, TextElement

class superscript(rawsource='', text='', *children, **attributes)[source]

Bases: Inline, TextElement

class subscript(rawsource='', text='', *children, **attributes)[source]

Bases: Inline, TextElement

class math(rawsource='', text='', *children, **attributes)[source]

Bases: Inline, TextElement

class image(rawsource='', *children, **attributes)[source]

Bases: General, Inline, Element

astext()[source]

Return a string representation of this Node.

class inline(rawsource='', text='', *children, **attributes)[source]

Bases: Inline, TextElement

class problematic(rawsource='', text='', *children, **attributes)[source]

Bases: Inline, TextElement

class generated(rawsource='', text='', *children, **attributes)[source]

Bases: Inline, TextElement

node_class_names = ['Text', 'abbreviation', 'acronym', 'address', 'admonition', 'attention', 'attribution', 'author', 'authors', 'block_quote', 'bullet_list', 'caption', 'caution', 'citation', 'citation_reference', 'classifier', 'colspec', 'comment', 'compound', 'contact', 'container', 'copyright', 'danger', 'date', 'decoration', 'definition', 'definition_list', 'definition_list_item', 'description', 'docinfo', 'doctest_block', 'document', 'emphasis', 'entry', 'enumerated_list', 'error', 'field', 'field_body', 'field_list', 'field_name', 'figure', 'footer', 'footnote', 'footnote_reference', 'generated', 'header', 'hint', 'image', 'important', 'inline', 'label', 'legend', 'line', 'line_block', 'list_item', 'literal', 'literal_block', 'math', 'math_block', 'meta', 'note', 'option', 'option_argument', 'option_group', 'option_list', 'option_list_item', 'option_string', 'organization', 'paragraph', 'pending', 'problematic', 'raw', 'reference', 'revision', 'row', 'rubric', 'section', 'sidebar', 'status', 'strong', 'subscript', 'substitution_definition', 'substitution_reference', 'subtitle', 'superscript', 'system_message', 'table', 'target', 'tbody', 'term', 'tgroup', 'thead', 'tip', 'title', 'title_reference', 'topic', 'transition', 'version', 'warning']

A list of names of all concrete Node subclasses.

class NodeVisitor(document)[source]

Bases: object

“Visitor” pattern [GoF95] abstract superclass implementation for document tree traversals.

Each node class has corresponding methods, doing nothing by default; override individual methods for specific and useful behaviour. The dispatch_visit() method is called by Node.walk() upon entering a node. Node.walkabout() also calls the dispatch_departure() method before exiting a node.

The dispatch methods call “visit_ + node class name” or “depart_ + node class name”, resp.

This is a base class for visitors whose visit_... & depart_... methods must be implemented for all compulsory node types encountered (such as for docutils.writers.Writer subclasses). Unimplemented methods will raise exceptions (except for optional nodes).

For sparse traversals, where only certain node types are of interest, use subclass SparseNodeVisitor instead. When (mostly or entirely) uniform processing is desired, subclass GenericNodeVisitor.

[GoF95]

Gamma, Helm, Johnson, Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, Reading, MA, USA, 1995.

optional = ('meta',)

Tuple containing node class names (as strings).

No exception will be raised if writers do not implement visit or departure functions for these node classes.

Used to ensure transitional compatibility with existing 3rd-party writers.

dispatch_visit(node)[source]

Call self.”visit_ + node class name” with node as parameter. If the visit_... method does not exist, call self.unknown_visit.

dispatch_departure(node)[source]

Call self.”depart_ + node class name” with node as parameter. If the depart_... method does not exist, call self.unknown_departure.

unknown_visit(node)[source]

Called when entering unknown Node types.

Raise an exception unless overridden.

unknown_departure(node)[source]

Called before exiting unknown Node types.

Raise exception unless overridden.

class SparseNodeVisitor(document)[source]

Bases: NodeVisitor

Base class for sparse traversals, where only certain node types are of interest. When visit_... & depart_... methods should be implemented for all node types (such as for docutils.writers.Writer subclasses), subclass NodeVisitor instead.

depart_Text(node)
depart_abbreviation(node)
depart_acks(node)
depart_acronym(node)
depart_address(node)
depart_admonition(node)
depart_attention(node)
depart_attribution(node)
depart_author(node)
depart_authors(node)
depart_block_quote(node)
depart_bullet_list(node)
depart_caption(node)
depart_caution(node)
depart_centered(node)
depart_citation(node)
depart_citation_reference(node)
depart_classifier(node)
depart_colspec(node)
depart_comment(node)
depart_compact_paragraph(node)
depart_compound(node)
depart_contact(node)
depart_container(node)
depart_danger(node)
depart_date(node)
depart_decoration(node)
depart_definition(node)
depart_definition_list(node)
depart_definition_list_item(node)
depart_desc(node)
depart_desc_addname(node)
depart_desc_annotation(node)
depart_desc_content(node)
depart_desc_inline(node)
depart_desc_name(node)
depart_desc_optional(node)
depart_desc_parameter(node)
depart_desc_parameterlist(node)
depart_desc_returns(node)
depart_desc_sig_keyword(node)
depart_desc_sig_keyword_type(node)
depart_desc_sig_literal_char(node)
depart_desc_sig_literal_number(node)
depart_desc_sig_literal_string(node)
depart_desc_sig_name(node)
depart_desc_sig_operator(node)
depart_desc_sig_punctuation(node)
depart_desc_sig_space(node)
depart_desc_signature(node)
depart_desc_signature_line(node)
depart_desc_type(node)
depart_desc_type_parameter(node)
depart_desc_type_parameter_list(node)
depart_description(node)
depart_docinfo(node)
depart_doctest_block(node)
depart_document(node)
depart_download_reference(node)
depart_emphasis(node)
depart_entry(node)
depart_enumerated_list(node)
depart_error(node)
depart_field(node)
depart_field_body(node)
depart_field_list(node)
depart_field_name(node)
depart_figure(node)
depart_footnote(node)
depart_footnote_reference(node)
depart_generated(node)
depart_glossary(node)
depart_header(node)
depart_highlightlang(node)
depart_hint(node)
depart_hlist(node)
depart_hlistcol(node)
depart_image(node)
depart_important(node)
depart_index(node)
depart_inline(node)
depart_label(node)
depart_legend(node)
depart_line(node)
depart_line_block(node)
depart_list_item(node)
depart_literal(node)
depart_literal_block(node)
depart_literal_emphasis(node)
depart_literal_strong(node)
depart_manpage(node)
depart_math(node)
depart_math_block(node)
depart_meta(node)
depart_note(node)
depart_number_reference(node)
depart_only(node)
depart_option(node)
depart_option_argument(node)
depart_option_group(node)
depart_option_list(node)
depart_option_list_item(node)
depart_option_string(node)
depart_organization(node)
depart_paragraph(node)
depart_pending(node)
depart_pending_xref(node)
depart_problematic(node)
depart_production(node)
depart_productionlist(node)
depart_raw(node)
depart_reference(node)
depart_revision(node)
depart_row(node)
depart_rubric(node)
depart_section(node)
depart_seealso(node)
depart_sidebar(node)
depart_start_of_file(node)
depart_status(node)
depart_strong(node)
depart_subscript(node)
depart_substitution_definition(node)
depart_substitution_reference(node)
depart_subtitle(node)
depart_superscript(node)
depart_system_message(node)
depart_table(node)
depart_tabular_col_spec(node)
depart_target(node)
depart_tbody(node)
depart_term(node)
depart_tgroup(node)
depart_thead(node)
depart_tip(node)
depart_title(node)
depart_title_reference(node)
depart_toctree(node)
depart_topic(node)
depart_transition(node)
depart_version(node)
depart_versionmodified(node)
depart_warning(node)
visit_Text(node)
visit_abbreviation(node)
visit_acks(node)
visit_acronym(node)
visit_address(node)
visit_admonition(node)
visit_attention(node)
visit_attribution(node)
visit_author(node)
visit_authors(node)
visit_block_quote(node)
visit_bullet_list(node)
visit_caption(node)
visit_caution(node)
visit_centered(node)
visit_citation(node)
visit_citation_reference(node)
visit_classifier(node)
visit_colspec(node)
visit_comment(node)
visit_compact_paragraph(node)
visit_compound(node)
visit_contact(node)
visit_container(node)
visit_danger(node)
visit_date(node)
visit_decoration(node)
visit_definition(node)
visit_definition_list(node)
visit_definition_list_item(node)
visit_desc(node)
visit_desc_addname(node)
visit_desc_annotation(node)
visit_desc_content(node)
visit_desc_inline(node)
visit_desc_name(node)
visit_desc_optional(node)
visit_desc_parameter(node)
visit_desc_parameterlist(node)
visit_desc_returns(node)
visit_desc_sig_keyword(node)
visit_desc_sig_keyword_type(node)
visit_desc_sig_literal_char(node)
visit_desc_sig_literal_number(node)
visit_desc_sig_literal_string(node)
visit_desc_sig_name(node)
visit_desc_sig_operator(node)
visit_desc_sig_punctuation(node)
visit_desc_sig_space(node)
visit_desc_signature(node)
visit_desc_signature_line(node)
visit_desc_type(node)
visit_desc_type_parameter(node)
visit_desc_type_parameter_list(node)
visit_description(node)
visit_docinfo(node)
visit_doctest_block(node)
visit_document(node)
visit_download_reference(node)
visit_emphasis(node)
visit_entry(node)
visit_enumerated_list(node)
visit_error(node)
visit_field(node)
visit_field_body(node)
visit_field_list(node)
visit_field_name(node)
visit_figure(node)
visit_footnote(node)
visit_footnote_reference(node)
visit_generated(node)
visit_glossary(node)
visit_header(node)
visit_highlightlang(node)
visit_hint(node)
visit_hlist(node)
visit_hlistcol(node)
visit_image(node)
visit_important(node)
visit_index(node)
visit_inline(node)
visit_label(node)
visit_legend(node)
visit_line(node)
visit_line_block(node)
visit_list_item(node)
visit_literal(node)
visit_literal_block(node)
visit_literal_emphasis(node)
visit_literal_strong(node)
visit_manpage(node)
visit_math(node)
visit_math_block(node)
visit_meta(node)
visit_note(node)
visit_number_reference(node)
visit_only(node)
visit_option(node)
visit_option_argument(node)
visit_option_group(node)
visit_option_list(node)
visit_option_list_item(node)
visit_option_string(node)
visit_organization(node)
visit_paragraph(node)
visit_pending(node)
visit_pending_xref(node)
visit_problematic(node)
visit_production(node)
visit_productionlist(node)
visit_raw(node)
visit_reference(node)
visit_revision(node)
visit_row(node)
visit_rubric(node)
visit_section(node)
visit_seealso(node)
visit_sidebar(node)
visit_start_of_file(node)
visit_status(node)
visit_strong(node)
visit_subscript(node)
visit_substitution_definition(node)
visit_substitution_reference(node)
visit_subtitle(node)
visit_superscript(node)
visit_system_message(node)
visit_table(node)
visit_tabular_col_spec(node)
visit_target(node)
visit_tbody(node)
visit_term(node)
visit_tgroup(node)
visit_thead(node)
visit_tip(node)
visit_title(node)
visit_title_reference(node)
visit_toctree(node)
visit_topic(node)
visit_transition(node)
visit_version(node)
visit_versionmodified(node)
visit_warning(node)
class GenericNodeVisitor(document)[source]

Bases: NodeVisitor

Generic “Visitor” abstract superclass, for simple traversals.

Unless overridden, each visit_... method calls default_visit(), and each depart_... method (when using Node.walkabout()) calls default_departure(). default_visit() (and default_departure()) must be overridden in subclasses.

Define fully generic visitors by overriding default_visit() (and default_departure()) only. Define semi-generic visitors by overriding individual visit_...() (and depart_...()) methods also.

NodeVisitor.unknown_visit() (NodeVisitor.unknown_departure()) should be overridden for default behavior.

depart_Text(node)
depart_abbreviation(node)
depart_acks(node)
depart_acronym(node)
depart_address(node)
depart_admonition(node)
depart_attention(node)
depart_attribution(node)
depart_author(node)
depart_authors(node)
depart_block_quote(node)
depart_bullet_list(node)
depart_caption(node)
depart_caution(node)
depart_centered(node)
depart_citation(node)
depart_citation_reference(node)
depart_classifier(node)
depart_colspec(node)
depart_comment(node)
depart_compact_paragraph(node)
depart_compound(node)
depart_contact(node)
depart_container(node)
depart_danger(node)
depart_date(node)
depart_decoration(node)
depart_definition(node)
depart_definition_list(node)
depart_definition_list_item(node)
depart_desc(node)
depart_desc_addname(node)
depart_desc_annotation(node)
depart_desc_content(node)
depart_desc_inline(node)
depart_desc_name(node)
depart_desc_optional(node)
depart_desc_parameter(node)
depart_desc_parameterlist(node)
depart_desc_returns(node)
depart_desc_sig_keyword(node)
depart_desc_sig_keyword_type(node)
depart_desc_sig_literal_char(node)
depart_desc_sig_literal_number(node)
depart_desc_sig_literal_string(node)
depart_desc_sig_name(node)
depart_desc_sig_operator(node)
depart_desc_sig_punctuation(node)
depart_desc_sig_space(node)
depart_desc_signature(node)
depart_desc_signature_line(node)
depart_desc_type(node)
depart_desc_type_parameter(node)
depart_desc_type_parameter_list(node)
depart_description(node)
depart_docinfo(node)
depart_doctest_block(node)
depart_document(node)
depart_download_reference(node)
depart_emphasis(node)
depart_entry(node)
depart_enumerated_list(node)
depart_error(node)
depart_field(node)
depart_field_body(node)
depart_field_list(node)
depart_field_name(node)
depart_figure(node)
depart_footnote(node)
depart_footnote_reference(node)
depart_generated(node)
depart_glossary(node)
depart_header(node)
depart_highlightlang(node)
depart_hint(node)
depart_hlist(node)
depart_hlistcol(node)
depart_image(node)
depart_important(node)
depart_index(node)
depart_inline(node)
depart_label(node)
depart_legend(node)
depart_line(node)
depart_line_block(node)
depart_list_item(node)
depart_literal(node)
depart_literal_block(node)
depart_literal_emphasis(node)
depart_literal_strong(node)
depart_manpage(node)
depart_math(node)
depart_math_block(node)
depart_meta(node)
depart_note(node)
depart_number_reference(node)
depart_only(node)
depart_option(node)
depart_option_argument(node)
depart_option_group(node)
depart_option_list(node)
depart_option_list_item(node)
depart_option_string(node)
depart_organization(node)
depart_paragraph(node)
depart_pending(node)
depart_pending_xref(node)
depart_problematic(node)
depart_production(node)
depart_productionlist(node)
depart_raw(node)
depart_reference(node)
depart_revision(node)
depart_row(node)
depart_rubric(node)
depart_section(node)
depart_seealso(node)
depart_sidebar(node)
depart_start_of_file(node)
depart_status(node)
depart_strong(node)
depart_subscript(node)
depart_substitution_definition(node)
depart_substitution_reference(node)
depart_subtitle(node)
depart_superscript(node)
depart_system_message(node)
depart_table(node)
depart_tabular_col_spec(node)
depart_target(node)
depart_tbody(node)
depart_term(node)
depart_tgroup(node)
depart_thead(node)
depart_tip(node)
depart_title(node)
depart_title_reference(node)
depart_toctree(node)
depart_topic(node)
depart_transition(node)
depart_version(node)
depart_versionmodified(node)
depart_warning(node)
visit_Text(node)
visit_abbreviation(node)
visit_acks(node)
visit_acronym(node)
visit_address(node)
visit_admonition(node)
visit_attention(node)
visit_attribution(node)
visit_author(node)
visit_authors(node)
visit_block_quote(node)
visit_bullet_list(node)
visit_caption(node)
visit_caution(node)
visit_centered(node)
visit_citation(node)
visit_citation_reference(node)
visit_classifier(node)
visit_colspec(node)
visit_comment(node)
visit_compact_paragraph(node)
visit_compound(node)
visit_contact(node)
visit_container(node)
visit_danger(node)
visit_date(node)
visit_decoration(node)
visit_definition(node)
visit_definition_list(node)
visit_definition_list_item(node)
visit_desc(node)
visit_desc_addname(node)
visit_desc_annotation(node)
visit_desc_content(node)
visit_desc_inline(node)
visit_desc_name(node)
visit_desc_optional(node)
visit_desc_parameter(node)
visit_desc_parameterlist(node)
visit_desc_returns(node)
visit_desc_sig_keyword(node)
visit_desc_sig_keyword_type(node)
visit_desc_sig_literal_char(node)
visit_desc_sig_literal_number(node)
visit_desc_sig_literal_string(node)
visit_desc_sig_name(node)
visit_desc_sig_operator(node)
visit_desc_sig_punctuation(node)
visit_desc_sig_space(node)
visit_desc_signature(node)
visit_desc_signature_line(node)
visit_desc_type(node)
visit_desc_type_parameter(node)
visit_desc_type_parameter_list(node)
visit_description(node)
visit_docinfo(node)
visit_doctest_block(node)
visit_document(node)
visit_download_reference(node)
visit_emphasis(node)
visit_entry(node)
visit_enumerated_list(node)
visit_error(node)
visit_field(node)
visit_field_body(node)
visit_field_list(node)
visit_field_name(node)
visit_figure(node)
visit_footnote(node)
visit_footnote_reference(node)
visit_generated(node)
visit_glossary(node)
visit_header(node)
visit_highlightlang(node)
visit_hint(node)
visit_hlist(node)
visit_hlistcol(node)
visit_image(node)
visit_important(node)
visit_index(node)
visit_inline(node)
visit_label(node)
visit_legend(node)
visit_line(node)
visit_line_block(node)
visit_list_item(node)
visit_literal(node)
visit_literal_block(node)
visit_literal_emphasis(node)
visit_literal_strong(node)
visit_manpage(node)
visit_math(node)
visit_math_block(node)
visit_meta(node)
visit_note(node)
visit_number_reference(node)
visit_only(node)
visit_option(node)
visit_option_argument(node)
visit_option_group(node)
visit_option_list(node)
visit_option_list_item(node)
visit_option_string(node)
visit_organization(node)
visit_paragraph(node)
visit_pending(node)
visit_pending_xref(node)
visit_problematic(node)
visit_production(node)
visit_productionlist(node)
visit_raw(node)
visit_reference(node)
visit_revision(node)
visit_row(node)
visit_rubric(node)
visit_section(node)
visit_seealso(node)
visit_sidebar(node)
visit_start_of_file(node)
visit_status(node)
visit_strong(node)
visit_subscript(node)
visit_substitution_definition(node)
visit_substitution_reference(node)
visit_subtitle(node)
visit_superscript(node)
visit_system_message(node)
visit_table(node)
visit_tabular_col_spec(node)
visit_target(node)
visit_tbody(node)
visit_term(node)
visit_tgroup(node)
visit_thead(node)
visit_tip(node)
visit_title(node)
visit_title_reference(node)
visit_toctree(node)
visit_topic(node)
visit_transition(node)
visit_version(node)
visit_versionmodified(node)
visit_warning(node)
default_visit(node)[source]

Override for generic, uniform traversals.

default_departure(node)[source]

Override for generic, uniform traversals.

_call_default_visit(self, node)[source]
_call_default_departure(self, node)[source]
_nop(self, node)[source]
_add_node_class_names(names)[source]

Save typing with dynamic assignments:

class TreeCopyVisitor(document)[source]

Bases: GenericNodeVisitor

Make a complete copy of a tree or branch, including element attributes.

get_tree_copy()[source]
default_visit(node)[source]

Copy the current node, and make it the new acting parent.

default_departure(node)[source]

Restore the previous acting parent.

exception TreePruningException[source]

Bases: Exception

Base class for NodeVisitor-related tree pruning exceptions.

Raise subclasses from within visit_... or depart_... methods called from Node.walk() and Node.walkabout() tree traversals to prune the tree traversed.

exception SkipChildren[source]

Bases: TreePruningException

Do not visit any children of the current node. The current node’s siblings and depart_... method are not affected.

exception SkipSiblings[source]

Bases: TreePruningException

Do not visit any more siblings (to the right) of the current node. The current node’s children and its depart_... method are not affected.

exception SkipNode[source]

Bases: TreePruningException

Do not visit the current node’s children, and do not call the current node’s depart_... method.

exception SkipDeparture[source]

Bases: TreePruningException

Do not call the current node’s depart_... method. The current node’s children and siblings are not affected.

exception NodeFound[source]

Bases: TreePruningException

Raise to indicate that the target of a search has been found. This exception must be caught by the client; it is not caught by the traversal code.

exception StopTraversal[source]

Bases: TreePruningException

Stop the traversal altogether. The current node’s depart_... method is not affected. The parent nodes depart_... methods are also called as usual. No other nodes are visited. This is an alternative to NodeFound that does not cause exception handling to trickle up to the caller.

make_id(string)[source]

Convert string into an identifier and return it.

Docutils identifiers will conform to the regular expression [a-z](-?[a-z0-9]+)*. For CSS compatibility, identifiers (the “class” and “id” attributes) should have no underscores, colons, or periods. Hyphens may be used.

  • The HTML 4.01 spec defines identifiers based on SGML tokens:

    ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (“-“), underscores (“_”), colons (“:”), and periods (“.”).

  • However the CSS1 spec defines identifiers based on the “name” token, a tighter interpretation (“flex” tokenizer notation; “latin1” and “escape” 8-bit characters have been replaced with entities):

    unicode     \[0-9a-f]{1,4}
    latin1      [&iexcl;-&yuml;]
    escape      {unicode}|\[ -~&iexcl;-&yuml;]
    nmchar      [-a-z0-9]|{latin1}|{escape}
    name        {nmchar}+
    

The CSS1 “nmchar” rule does not include underscores (“_”), colons (“:”), or periods (“.”), therefore “class” and “id” attributes should not contain these characters. They should be replaced with hyphens (“-“). Combined with HTML’s requirements (the first character must be a letter; no “unicode”, “latin1”, or “escape” characters), this results in the [a-z](-?[a-z0-9]+)* pattern.

dupname(node, name)[source]
fully_normalize_name(name)[source]

Return a case- and whitespace-normalized name.

whitespace_normalize_name(name)[source]

Return a whitespace-normalized name.

serial_escape(value)[source]

Escape string values that are elements of a list, for serialization.

pseudo_quoteattr(value)[source]

Quote attributes for pseudo-xml