user clearer variable names for indent type and indent depth
This commit is contained in:
parent
843706be39
commit
7249ae8b0a
1 changed files with 10 additions and 11 deletions
|
|
@ -3201,21 +3201,20 @@ def chooseQuoteCharacter(str):
|
||||||
# - pretty printing
|
# - pretty printing
|
||||||
# - somewhat judicious use of whitespace
|
# - somewhat judicious use of whitespace
|
||||||
# - ensure id attributes are first
|
# - ensure id attributes are first
|
||||||
def serializeXML(element, options, ind=0, preserveWhitespace=False):
|
def serializeXML(element, options, indent_depth=0, preserveWhitespace=False):
|
||||||
outParts = []
|
outParts = []
|
||||||
|
|
||||||
indent = ind
|
indent_type = ''
|
||||||
line_prefix = ''
|
|
||||||
newline = ''
|
newline = ''
|
||||||
if options.newlines:
|
if options.newlines:
|
||||||
if options.indent_type == 'tab':
|
if options.indent_type == 'tab':
|
||||||
line_prefix = '\t'
|
indent_type = '\t'
|
||||||
elif options.indent_type == 'space':
|
elif options.indent_type == 'space':
|
||||||
line_prefix = ' '
|
indent_type = ' '
|
||||||
line_prefix *= options.indent_depth
|
indent_type *= options.indent_depth
|
||||||
newline = '\n'
|
newline = '\n'
|
||||||
|
|
||||||
outParts.extend([(line_prefix * ind), '<', element.nodeName])
|
outParts.extend([(indent_type * indent_depth), '<', element.nodeName])
|
||||||
|
|
||||||
# now serialize the other attributes
|
# now serialize the other attributes
|
||||||
known_attr = [
|
known_attr = [
|
||||||
|
|
@ -3270,7 +3269,7 @@ def serializeXML(element, options, ind=0, preserveWhitespace=False):
|
||||||
children = element.childNodes
|
children = element.childNodes
|
||||||
if children.length == 0:
|
if children.length == 0:
|
||||||
outParts.append('/>')
|
outParts.append('/>')
|
||||||
if indent > 0:
|
if indent_depth > 0:
|
||||||
outParts.append(newline)
|
outParts.append(newline)
|
||||||
else:
|
else:
|
||||||
outParts.append('>')
|
outParts.append('>')
|
||||||
|
|
@ -3282,7 +3281,7 @@ def serializeXML(element, options, ind=0, preserveWhitespace=False):
|
||||||
if preserveWhitespace:
|
if preserveWhitespace:
|
||||||
outParts.append(serializeXML(child, options, 0, preserveWhitespace))
|
outParts.append(serializeXML(child, options, 0, preserveWhitespace))
|
||||||
else:
|
else:
|
||||||
outParts.extend([newline, serializeXML(child, options, indent + 1, preserveWhitespace)])
|
outParts.extend([newline, serializeXML(child, options, indent_depth + 1, preserveWhitespace)])
|
||||||
onNewLine = True
|
onNewLine = True
|
||||||
# text node
|
# text node
|
||||||
elif child.nodeType == Node.TEXT_NODE:
|
elif child.nodeType == Node.TEXT_NODE:
|
||||||
|
|
@ -3303,9 +3302,9 @@ def serializeXML(element, options, ind=0, preserveWhitespace=False):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if onNewLine:
|
if onNewLine:
|
||||||
outParts.append(line_prefix * ind)
|
outParts.append(indent_type * indent_depth)
|
||||||
outParts.extend(['</', element.nodeName, '>'])
|
outParts.extend(['</', element.nodeName, '>'])
|
||||||
if indent > 0:
|
if indent_depth > 0:
|
||||||
outParts.append(newline)
|
outParts.append(newline)
|
||||||
|
|
||||||
return "".join(outParts)
|
return "".join(outParts)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue