Format output XML prettily
This commit is contained in:
parent
066c627833
commit
359c42166f
4 changed files with 37 additions and 7 deletions
21
scour.py
21
scour.py
|
|
@ -47,11 +47,9 @@
|
||||||
# * Collapse all group based transformations
|
# * Collapse all group based transformations
|
||||||
|
|
||||||
# Next Up:
|
# Next Up:
|
||||||
# + moved all functionality into a module level function named 'scour' and only call it
|
|
||||||
# when being run as main (for unit testing)
|
|
||||||
# + prevent metadata from being removed if they contain only text nodes
|
|
||||||
# - Remove unreferenced pattern elements
|
|
||||||
# - Remove duplicate gradient stops
|
# - Remove duplicate gradient stops
|
||||||
|
# - Remove unnecessary nested <g> elements
|
||||||
|
# - Pretty up whitespace nodes on output
|
||||||
# - Convert all colors to #RRGGBB format
|
# - Convert all colors to #RRGGBB format
|
||||||
# - rework command-line argument processing so that options are configurable
|
# - rework command-line argument processing so that options are configurable
|
||||||
# - remove unreferenced patterns? https://bugs.edge.launchpad.net/ubuntu/+source/human-icon-theme/+bug/361667/
|
# - remove unreferenced patterns? https://bugs.edge.launchpad.net/ubuntu/+source/human-icon-theme/+bug/361667/
|
||||||
|
|
@ -644,9 +642,18 @@ def scourString(in_string):
|
||||||
# properly size the SVG document (ideally width/height should be 100% with a viewBox)
|
# properly size the SVG document (ideally width/height should be 100% with a viewBox)
|
||||||
properlySizeDoc(doc.documentElement)
|
properlySizeDoc(doc.documentElement)
|
||||||
|
|
||||||
# output the document
|
# output the document as a pretty string with a single space for indent
|
||||||
out_string = doc.documentElement.toxml()
|
out_string = doc.documentElement.toprettyxml(' ')
|
||||||
return out_string
|
|
||||||
|
# now strip out empty lines
|
||||||
|
lines = []
|
||||||
|
# Get rid of empty lines
|
||||||
|
for line in out_string.splitlines(True):
|
||||||
|
if line.strip():
|
||||||
|
lines.append(line)
|
||||||
|
|
||||||
|
# return the string stripped of empty lines
|
||||||
|
return "".join(lines)
|
||||||
|
|
||||||
# used mostly by unit tests
|
# used mostly by unit tests
|
||||||
# input is a filename
|
# input is a filename
|
||||||
|
|
|
||||||
13
testscour.py
13
testscour.py
|
|
@ -126,6 +126,19 @@ class RemoveUnreferencedPattern(unittest.TestCase):
|
||||||
self.assertEquals(len(doc.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'pattern')), 0,
|
self.assertEquals(len(doc.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'pattern')), 0,
|
||||||
'Unreferenced pattern not removed' )
|
'Unreferenced pattern not removed' )
|
||||||
|
|
||||||
|
class RemoveUnreferencedLinearGradient(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
doc = scour.scourXmlFile('unittests/unreferenced-linearGradient.svg')
|
||||||
|
self.assertEquals(len(doc.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient')), 0,
|
||||||
|
'Unreferenced linearGradient not removed' )
|
||||||
|
|
||||||
|
class RemoveUnreferencedRadialGradient(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
doc = scour.scourXmlFile('unittests/unreferenced-radialGradient.svg')
|
||||||
|
self.assertEquals(len(doc.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'radialradient')), 0,
|
||||||
|
'Unreferenced radialGradient not removed' )
|
||||||
|
|
||||||
|
|
||||||
# These tests will fail at present
|
# These tests will fail at present
|
||||||
#class RemoveDuplicateGradientStops(unittest.TestCase):
|
#class RemoveDuplicateGradientStops(unittest.TestCase):
|
||||||
# def runTest(self):
|
# def runTest(self):
|
||||||
|
|
|
||||||
5
unittests/unreferenced-linearGradient.svg
Normal file
5
unittests/unreferenced-linearGradient.svg
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<linearGradient id="Polka_Dot_Pattern">
|
||||||
|
<stop offset="0.5" stop-color="blue" />
|
||||||
|
</linearGradient>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 147 B |
5
unittests/unreferenced-radialGradient.svg
Normal file
5
unittests/unreferenced-radialGradient.svg
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<radialGradient id="Polka_Dot_Pattern">
|
||||||
|
<stop offset="0.5" stop-color="blue" />
|
||||||
|
</radialGradient>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 147 B |
Loading…
Add table
Add a link
Reference in a new issue