The dom.indent module

Functionality to pretty-print a DOM document, with good default indentation.

class Indenter(indent_width=2, start_indent=0, max_align_indent=16)[source]

Bases: object

Prints the indented output of a node.

Indentation preferences can be given on instantiation or by setting the attributes of the same name.

The default indent_width can be given, and the additional start_indent which is prepended to every output line, both in number of spaces and defaulting to 0.

The max_align_indent argument determines the number of spaces used at most to align indenting lines with text on previous lines. If the number is exceeded, the default indent_width is used instead on such lines.

Call write() to get the indented text output of a node.

indent_width

the default indent width

start_indent

the number of spaces to prepend to every output line

max_align_indent

the maximum number of spaces to indent to align a line with certain text on the previous line

write(node)[source]

Get the indented output of the node.

Called by Element.write_indented().

output_node(node, index=-1)[source]

(Internal.) Output one node and its children.

The index, if given, is the index of this node in its parent. This is used to get additional indenting hints for the node.

add_whitespace(whitespace)[source]

(Internal.) Add whitespace, which is combined as soon as text is printed out.

enter_indent(node)[source]

(Internal.) Enter a new indent level for the node.

leave_indent()[source]

(Internal.) Leave the younghest indent level.

current_indent()[source]

(Internal.) Get the current indent (including start_indent) in nr of spaces.

create_new_block()[source]

(Internal.) Go to a new line.

output_space()[source]

(Internal.) Output whitespace. Newlines start a new output line.

output_head(text, index=-1, override=None)[source]

(Internal.) Output head text.

The index, if given, is the index of the node in its parent. This is used to get additional indenting hints for the node.

If override is not None, and this head text happens to be the first on a new line, this value is used as the indent depth for this line, in stead of the current indent.

output_tail(text)[source]

(Internal.) Output the tail text.