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:
objectPrints 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_widthcan be given, and the additionalstart_indentwhich is prepended to every output line, both in number of spaces and defaulting to 0.The
max_align_indentargument determines the number of spaces used at most to align indenting lines with text on previous lines. If the number is exceeded, the defaultindent_widthis used instead on such lines.Call
write()to get the indented text output of a node.-
indent_width= None¶ the default indent width
-
start_indent= None¶ the number of spaces to prepend to every output line
-
max_align_indent= None¶ 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.
-
current_indent()[source]¶ (Internal.) Get the current indent (including
start_indent) in nr of spaces.
-
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
overrideis 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.
-