diff --git a/release-notes.html b/release-notes.html index 140682c..7bee3c6 100644 --- a/release-notes.html +++ b/release-notes.html @@ -7,7 +7,7 @@

Scour Release Notes

-

Copyright 2009, Jeff Schiller

+

Copyright 2010, Jeff Schiller

@@ -16,6 +16,8 @@

2010-02-04

diff --git a/scour.py b/scour.py index bff9e2f..a269c14 100755 --- a/scour.py +++ b/scour.py @@ -34,8 +34,8 @@ # at rounded corners) # Next Up: +# - Bug 511186: option to keep XML comments between prolog and root element # - only remove unreferenced elements if they are not children of a referenced element -# - TODO: fix the removal of comment elements (between and ) # - add an option to remove ids if they match the Inkscape-style of IDs # - investigate point-reducing algorithms # - parse transform attribute @@ -2289,13 +2289,20 @@ def scourString(in_string, options=None): if line.strip(): lines.append(line) - # return the string stripped of empty lines + # return the string with its XML prolog and surrounding comments if options.strip_xml_prolog == False: - xmlprolog = '' + os.linesep + total_output = '' + os.linesep else: - xmlprolog = "" + total_output = "" + + # Find all comments before and after the root node and print them + for child in doc.childNodes: + if child.nodeType == 8: + total_output += ('' + os.linesep) + else: + total_output += "".join(lines) - return xmlprolog + "".join(lines) + return total_output # used mostly by unit tests # input is a filename diff --git a/testscour.py b/testscour.py index 126b4d3..880687e 100755 --- a/testscour.py +++ b/testscour.py @@ -987,7 +987,16 @@ class XmlEntities(unittest.TestCase): def runTest(self): self.assertEquals( scour.makeWellFormed('<>&"\''), '<>&"'', 'Incorrectly translated XML entities') - + +class DoNotStripCommentsOutsideOfRoot(unittest.TestCase): + def runTest(self): + doc = scour.scourXmlFile('unittests/comments.svg') + self.assertEquals( doc.childNodes.length, 4, + 'Did not include all comment children outside of root') + self.assertEquals( doc.childNodes[0].nodeType, 8, 'First node not a comment') + self.assertEquals( doc.childNodes[1].nodeType, 8, 'Second node not a comment') + self.assertEquals( doc.childNodes[3].nodeType, 8, 'Fourth node not a comment') + # TODO: write tests for --enable-viewboxing # TODO; write a test for embedding rasters # TODO: write a test for --disable-embed-rasters