docutils.transforms.universal module

Transforms needed by most or all documents:

  • Decorations: Generate a document’s header & footer.

  • ExposeInternals: Expose internal attributes.

  • Messages: Placement of system messages generated after parsing.

  • FilterMessages: Remove system messages below verbosity threshold.

  • TestMessages: Like Messages, used on test runs.

  • StripComments: Remove comment elements from the document tree.

  • StripClassesAndElements: Remove elements with classes in self.document.settings.strip_elements_with_classes and class values in self.document.settings.strip_classes.

  • SmartQuotes: Replace ASCII quotation marks with typographic form.

class Decorations(document, startnode=None)[source]

Bases: Transform

Populate a document’s decoration element (header, footer).

default_priority = 820

Numerical priority of this transform, 0 through 999 (override).

apply()[source]

Override to apply the transform to the document tree.

generate_header()[source]
class ExposeInternals(document, startnode=None)[source]

Bases: Transform

Expose internal attributes if expose_internals setting is set.

default_priority = 840

Numerical priority of this transform, 0 through 999 (override).

not_Text(node)[source]
apply()[source]

Override to apply the transform to the document tree.

class Messages(document, startnode=None)[source]

Bases: Transform

Place any system messages generated after parsing into a dedicated section of the document.

default_priority = 860

Numerical priority of this transform, 0 through 999 (override).

apply()[source]

Override to apply the transform to the document tree.

class FilterMessages(document, startnode=None)[source]

Bases: Transform

Remove system messages below verbosity threshold.

Convert <problematic> nodes referencing removed messages to <Text>. Remove “System Messages” section if empty.

default_priority = 870

Numerical priority of this transform, 0 through 999 (override).

apply()[source]

Override to apply the transform to the document tree.

class TestMessages(document, startnode=None)[source]

Bases: Transform

Append all post-parse system messages to the end of the document.

Used for testing purposes.

default_priority = 880

Numerical priority of this transform, 0 through 999 (override).

apply()[source]

Override to apply the transform to the document tree.

class StripComments(document, startnode=None)[source]

Bases: Transform

Remove comment elements from the document tree (only if the strip_comments setting is enabled).

default_priority = 740

Numerical priority of this transform, 0 through 999 (override).

apply()[source]

Override to apply the transform to the document tree.

class StripClassesAndElements(document, startnode=None)[source]

Bases: Transform

Remove from the document tree all elements with classes in self.document.settings.strip_elements_with_classes and all “classes” attribute values in self.document.settings.strip_classes.

default_priority = 420

Numerical priority of this transform, 0 through 999 (override).

apply()[source]

Override to apply the transform to the document tree.

check_classes(node)[source]
class SmartQuotes(document, startnode)[source]

Bases: Transform

Replace ASCII quotation marks with typographic form.

Also replace multiple dashes with em-dash/en-dash characters.

default_priority = 855

Numerical priority of this transform, 0 through 999 (override).

nodes_to_skip = (<class 'docutils.nodes.FixedTextElement'>, <class 'docutils.nodes.Special'>)

Do not apply “smartquotes” to instances of these block-level nodes.

literal_nodes = (<class 'docutils.nodes.FixedTextElement'>, <class 'docutils.nodes.Special'>, <class 'docutils.nodes.image'>, <class 'docutils.nodes.literal'>, <class 'docutils.nodes.math'>, <class 'docutils.nodes.raw'>, <class 'docutils.nodes.problematic'>)

Do not apply smartquotes to instances of these inline nodes.

smartquotes_action = 'qDe'

Setting to select smartquote transformations.

The default ‘qDe’ educates normal quote characters: (”, ‘), em- and en-dashes (—, –) and ellipses (…).

get_tokens(txtnodes)[source]
apply()[source]

Override to apply the transform to the document tree.