Add an option to suppress output of line breaks
(obviously this also disables indentation)
This commit is contained in:
parent
18266ca1ec
commit
e21e362353
1 changed files with 12 additions and 6 deletions
|
|
@ -2763,9 +2763,12 @@ def serializeXML(element, options, ind = 0, preserveWhitespace = False):
|
||||||
|
|
||||||
indent = ind
|
indent = ind
|
||||||
I=''
|
I=''
|
||||||
|
newline = ''
|
||||||
|
if options.newlines:
|
||||||
if options.indent_type == 'tab': I='\t'
|
if options.indent_type == 'tab': I='\t'
|
||||||
elif options.indent_type == 'space': I=' '
|
elif options.indent_type == 'space': I=' '
|
||||||
I *= options.indent_depth
|
I *= options.indent_depth
|
||||||
|
newline = '\n'
|
||||||
|
|
||||||
outParts.extend([(I * ind), '<', element.nodeName])
|
outParts.extend([(I * ind), '<', element.nodeName])
|
||||||
|
|
||||||
|
|
@ -2824,7 +2827,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(['\n', serializeXML(child, options, indent + 1, preserveWhitespace)])
|
outParts.extend([newline, serializeXML(child, options, indent + 1, preserveWhitespace)])
|
||||||
onNewLine = True
|
onNewLine = True
|
||||||
# text node
|
# text node
|
||||||
elif child.nodeType == 3:
|
elif child.nodeType == 3:
|
||||||
|
|
@ -2846,10 +2849,10 @@ def serializeXML(element, options, ind = 0, preserveWhitespace = False):
|
||||||
|
|
||||||
if onNewLine: outParts.append(I * ind)
|
if onNewLine: outParts.append(I * ind)
|
||||||
outParts.extend(['</', element.nodeName, '>'])
|
outParts.extend(['</', element.nodeName, '>'])
|
||||||
if indent > 0: outParts.append('\n')
|
if indent > 0: outParts.append(newline)
|
||||||
else:
|
else:
|
||||||
outParts.append('/>')
|
outParts.append('/>')
|
||||||
if indent > 0: outParts.append('\n')
|
if indent > 0: outParts.append(newline)
|
||||||
|
|
||||||
return "".join(outParts)
|
return "".join(outParts)
|
||||||
|
|
||||||
|
|
@ -3168,6 +3171,9 @@ _options_parser.add_option("--indent",
|
||||||
_options_parser.add_option("--nindent",
|
_options_parser.add_option("--nindent",
|
||||||
action="store", type=int, dest="indent_depth", default=1,
|
action="store", type=int, dest="indent_depth", default=1,
|
||||||
help="depth of the indentation, i.e. number of spaces/tabs: (default: %default)")
|
help="depth of the indentation, i.e. number of spaces/tabs: (default: %default)")
|
||||||
|
_options_parser.add_option("--no-line-breaks",
|
||||||
|
action="store_false", dest="newlines", default=True,
|
||||||
|
help="do not create line breaks in output (also disables indentation; might be overriden by xml:space=\"preserve\")")
|
||||||
_options_parser.add_option("--protect-ids-noninkscape",
|
_options_parser.add_option("--protect-ids-noninkscape",
|
||||||
action="store_true", dest="protect_ids_noninkscape", default=False,
|
action="store_true", dest="protect_ids_noninkscape", default=False,
|
||||||
help="Don't change IDs not ending with a digit")
|
help="Don't change IDs not ending with a digit")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue