Fix bug 717826, whereby newlines are output as CR CR LF by Scour on Inkscape/Windows when they should be LF or CR LF. Now they're output as CR LF, and standalone Scour outputs LF.

This commit is contained in:
Louis Simard 2011-02-16 12:27:23 -05:00
parent 4657cb7515
commit 48776271d7

View file

@ -2680,7 +2680,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([os.linesep, serializeXML(child, options, indent + 1, preserveWhitespace)]) outParts.extend(['\n', serializeXML(child, options, indent + 1, preserveWhitespace)])
onNewLine = True onNewLine = True
# text node # text node
elif child.nodeType == 3: elif child.nodeType == 3:
@ -2702,10 +2702,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(os.linesep) if indent > 0: outParts.append('\n')
else: else:
outParts.append('/>') outParts.append('/>')
if indent > 0: outParts.append(os.linesep) if indent > 0: outParts.append('\n')
return "".join(outParts) return "".join(outParts)
@ -2897,7 +2897,7 @@ def scourString(in_string, options=None):
# http://ronrothman.com/public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/ # http://ronrothman.com/public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/
# rolled our own serialize function here to save on space, put id first, customize indentation, etc # rolled our own serialize function here to save on space, put id first, customize indentation, etc
# out_string = doc.documentElement.toprettyxml(' ') # out_string = doc.documentElement.toprettyxml(' ')
out_string = serializeXML(doc.documentElement, options) + os.linesep out_string = serializeXML(doc.documentElement, options) + '\n'
# now strip out empty lines # now strip out empty lines
lines = [] lines = []
@ -2908,7 +2908,7 @@ def scourString(in_string, options=None):
# return the string with its XML prolog and surrounding comments # return the string with its XML prolog and surrounding comments
if options.strip_xml_prolog == False: if options.strip_xml_prolog == False:
total_output = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' + os.linesep total_output = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
else: else:
total_output = "" total_output = ""
@ -2916,7 +2916,7 @@ def scourString(in_string, options=None):
if child.nodeType == 1: if child.nodeType == 1:
total_output += "".join(lines) total_output += "".join(lines)
else: # doctypes, entities, comments else: # doctypes, entities, comments
total_output += child.toxml() + os.linesep total_output += child.toxml() + '\n'
return total_output return total_output
@ -3033,7 +3033,7 @@ def parse_args(args=None):
# GZ: could sniff for gzip compression here # GZ: could sniff for gzip compression here
infile = sys.stdin infile = sys.stdin
if options.outfilename: if options.outfilename:
outfile = maybe_gziped_file(options.outfilename, "w") outfile = maybe_gziped_file(options.outfilename, "wb")
else: else:
outfile = sys.stdout outfile = sys.stdout