Attempt to handle line endings in a cross-platform manner
This commit is contained in:
parent
de6c2eb924
commit
4198961174
5 changed files with 40 additions and 21 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
SCOURVER="0.22"
|
SCOURVER="0.23"
|
||||||
cd ..
|
cd ..
|
||||||
zip scour/tarballs/scour-$SCOURVER.zip scour/scour.py scour/yocto_css.py scour/svg_regex.py scour/LICENSE scour/NOTICE scour/README.txt scour/release-notes.html
|
zip scour/tarballs/scour-$SCOURVER.zip scour/scour.py scour/yocto_css.py scour/svg_regex.py scour/LICENSE scour/NOTICE scour/README.txt scour/release-notes.html
|
||||||
cd scour
|
cd scour
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,16 @@
|
||||||
|
|
||||||
<p>Copyright 2009, Jeff Schiller</p>
|
<p>Copyright 2009, Jeff Schiller</p>
|
||||||
|
|
||||||
|
<section id="0.23">
|
||||||
|
<header>
|
||||||
|
<h2><a href="#0.23">Version 0.23</a></h2>
|
||||||
|
</header>
|
||||||
|
<p>TBD</p>
|
||||||
|
<ul>
|
||||||
|
<li>...</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section id="0.22">
|
<section id="0.22">
|
||||||
<header>
|
<header>
|
||||||
<h2><a href="#0.22">Version 0.22</a></h2>
|
<h2><a href="#0.22">Version 0.22</a></h2>
|
||||||
|
|
|
||||||
30
scour.py
30
scour.py
|
|
@ -2092,7 +2092,7 @@ def serializeXML(element, options, ind = 0, preserveWhitespace = False):
|
||||||
if preserveWhitespace:
|
if preserveWhitespace:
|
||||||
outString += serializeXML(child, options, 0, preserveWhitespace)
|
outString += serializeXML(child, options, 0, preserveWhitespace)
|
||||||
else:
|
else:
|
||||||
outString += '\n' + serializeXML(child, options, indent + 1, preserveWhitespace)
|
outString += os.linesep + serializeXML(child, options, indent + 1, preserveWhitespace)
|
||||||
onNewLine = True
|
onNewLine = True
|
||||||
# text node
|
# text node
|
||||||
elif child.nodeType == 3:
|
elif child.nodeType == 3:
|
||||||
|
|
@ -2114,10 +2114,10 @@ def serializeXML(element, options, ind = 0, preserveWhitespace = False):
|
||||||
|
|
||||||
if onNewLine: outString += (I * ind)
|
if onNewLine: outString += (I * ind)
|
||||||
outString += '</' + element.nodeName + '>'
|
outString += '</' + element.nodeName + '>'
|
||||||
if indent > 0: outString += '\n'
|
if indent > 0: outString += os.linesep
|
||||||
else:
|
else:
|
||||||
outString += '/>'
|
outString += '/>'
|
||||||
if indent > 0: outString += '\n'
|
if indent > 0: outString += os.linesep
|
||||||
|
|
||||||
return outString
|
return outString
|
||||||
|
|
||||||
|
|
@ -2273,7 +2273,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)
|
out_string = serializeXML(doc.documentElement, options) + os.linesep
|
||||||
|
|
||||||
# now strip out empty lines
|
# now strip out empty lines
|
||||||
lines = []
|
lines = []
|
||||||
|
|
@ -2284,7 +2284,7 @@ def scourString(in_string, options=None):
|
||||||
|
|
||||||
# return the string stripped of empty lines
|
# return the string stripped of empty lines
|
||||||
if options.strip_xml_prolog == False:
|
if options.strip_xml_prolog == False:
|
||||||
xmlprolog = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
|
xmlprolog = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' + os.linesep
|
||||||
else:
|
else:
|
||||||
xmlprolog = ""
|
xmlprolog = ""
|
||||||
|
|
||||||
|
|
@ -2385,15 +2385,15 @@ def parse_args(args=None):
|
||||||
return options, [infile, outfile]
|
return options, [infile, outfile]
|
||||||
|
|
||||||
def getReport():
|
def getReport():
|
||||||
return ' Number of elements removed: ' + str(numElemsRemoved) + \
|
return ' Number of elements removed: ' + str(numElemsRemoved) + os.linesep + \
|
||||||
'\n Number of attributes removed: ' + str(numAttrsRemoved) + \
|
' Number of attributes removed: ' + str(numAttrsRemoved) + os.linesep + \
|
||||||
'\n Number of unreferenced id attributes removed: ' + str(numIDsRemoved) + \
|
' Number of unreferenced id attributes removed: ' + str(numIDsRemoved) + os.linesep + \
|
||||||
'\n Number of style properties fixed: ' + str(numStylePropsFixed) + \
|
' Number of style properties fixed: ' + str(numStylePropsFixed) + os.linesep + \
|
||||||
'\n Number of raster images embedded inline: ' + str(numRastersEmbedded) + \
|
' Number of raster images embedded inline: ' + str(numRastersEmbedded) + os.linesep + \
|
||||||
'\n Number of path segments reduced/removed: ' + str(numPathSegmentsReduced) + \
|
' Number of path segments reduced/removed: ' + str(numPathSegmentsReduced) + os.linesep + \
|
||||||
'\n Number of bytes saved in path data: ' + str(numBytesSavedInPathData) + \
|
' Number of bytes saved in path data: ' + str(numBytesSavedInPathData) + os.linesep + \
|
||||||
'\n Number of bytes saved in colors: ' + str(numBytesSavedInColors) + \
|
' Number of bytes saved in colors: ' + str(numBytesSavedInColors) + os.linesep + \
|
||||||
'\n Number of points removed from polygons: ' + str(numPointsRemovedFromPolygon)
|
' Number of points removed from polygons: ' + str(numPointsRemovedFromPolygon)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
|
|
@ -2423,7 +2423,7 @@ if __name__ == '__main__':
|
||||||
# GZ: unless silenced by -q or something?
|
# GZ: unless silenced by -q or something?
|
||||||
# GZ: not using globals would be good too
|
# GZ: not using globals would be good too
|
||||||
print >>sys.stderr, ' File:', input.name, \
|
print >>sys.stderr, ' File:', input.name, \
|
||||||
'\n Time taken:', str(end-start) + 's\n', \
|
os.linesep + ' Time taken:', str(end-start) + 's' + os.linesep, \
|
||||||
getReport()
|
getReport()
|
||||||
|
|
||||||
oldsize = len(in_string)
|
oldsize = len(in_string)
|
||||||
|
|
|
||||||
17
testscour.py
17
testscour.py
|
|
@ -834,7 +834,8 @@ class CDATAInXml(unittest.TestCase):
|
||||||
<script type="application/ecmascript"><![CDATA[
|
<script type="application/ecmascript"><![CDATA[
|
||||||
alert('pb&j');
|
alert('pb&j');
|
||||||
]]></script>
|
]]></script>
|
||||||
</svg>''',
|
</svg>
|
||||||
|
''',
|
||||||
'Improperly serialized the cdata unit tests')
|
'Improperly serialized the cdata unit tests')
|
||||||
|
|
||||||
class WellFormedXMLLesserThanInAttrValue(unittest.TestCase):
|
class WellFormedXMLLesserThanInAttrValue(unittest.TestCase):
|
||||||
|
|
@ -933,7 +934,8 @@ class DoNotPrettyPrintWhenWhitespacePreserved(unittest.TestCase):
|
||||||
'''<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
'''<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg">
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
<text xml:space="preserve">This is some <tspan font-style="italic">messed-up</tspan> markup</text>
|
<text xml:space="preserve">This is some <tspan font-style="italic">messed-up</tspan> markup</text>
|
||||||
</svg>''',
|
</svg>
|
||||||
|
''',
|
||||||
'Whitespace not preserved')
|
'Whitespace not preserved')
|
||||||
|
|
||||||
class DoNotPrettyPrintWhenNestedWhitespacePreserved(unittest.TestCase):
|
class DoNotPrettyPrintWhenNestedWhitespacePreserved(unittest.TestCase):
|
||||||
|
|
@ -942,7 +944,8 @@ class DoNotPrettyPrintWhenNestedWhitespacePreserved(unittest.TestCase):
|
||||||
'''<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
'''<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg">
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
<text xml:space="preserve"><tspan font-style="italic">Use <tspan font-style="bold">bold</tspan> text</tspan></text>
|
<text xml:space="preserve"><tspan font-style="italic">Use <tspan font-style="bold">bold</tspan> text</tspan></text>
|
||||||
</svg>''',
|
</svg>
|
||||||
|
''',
|
||||||
'Whitespace not preserved when nested')
|
'Whitespace not preserved when nested')
|
||||||
|
|
||||||
class GetAttrPrefixRight(unittest.TestCase):
|
class GetAttrPrefixRight(unittest.TestCase):
|
||||||
|
|
@ -954,7 +957,7 @@ class GetAttrPrefixRight(unittest.TestCase):
|
||||||
class EnsurePreserveWhitespaceOnNonTextElements(unittest.TestCase):
|
class EnsurePreserveWhitespaceOnNonTextElements(unittest.TestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
s = scour.scourString(open('unittests/no-collapse-lines.svg').read())
|
s = scour.scourString(open('unittests/no-collapse-lines.svg').read())
|
||||||
self.assertEquals( s.count('\n'), 5,
|
self.assertEquals( len(s.splitlines()), 6,
|
||||||
'Did not properly preserve whitespace on elements even if they were not textual')
|
'Did not properly preserve whitespace on elements even if they were not textual')
|
||||||
|
|
||||||
class HandleEmptyStyleElement(unittest.TestCase):
|
class HandleEmptyStyleElement(unittest.TestCase):
|
||||||
|
|
@ -967,6 +970,12 @@ class HandleEmptyStyleElement(unittest.TestCase):
|
||||||
self.assertEquals( fail, False,
|
self.assertEquals( fail, False,
|
||||||
'Could not handle an empty style element')
|
'Could not handle an empty style element')
|
||||||
|
|
||||||
|
class EnsureLineEndings(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
s = scour.scourString(open('unittests/whitespace-important.svg').read())
|
||||||
|
self.assertEquals( len(s.splitlines()), 4,
|
||||||
|
'Did not output line ending character correctly')
|
||||||
|
|
||||||
# TODO; write a test for embedding rasters
|
# TODO; write a test for embedding rasters
|
||||||
# TODO: write a test for --disable-embed-rasters
|
# TODO: write a test for --disable-embed-rasters
|
||||||
# TODO: write tests for --keep-editor-data
|
# TODO: write tests for --keep-editor-data
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg">
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
<text xml:space="preserve">This is some <tspan font-style="italic">messed-up</tspan> markup</text>
|
<text xml:space="preserve">This is some <tspan font-style="italic">messed-up</tspan> markup</text>
|
||||||
</svg>
|
</svg>
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 202 B After Width: | Height: | Size: 203 B |
Loading…
Add table
Add a link
Reference in a new issue