Fix Bug 511186: Preserve comments surround <svg> root node

This commit is contained in:
JSCHILL1 2010-02-04 19:31:54 -06:00
parent 6147bb2085
commit c835423e8f
3 changed files with 25 additions and 7 deletions

View file

@ -7,7 +7,7 @@
<h1><a href="http://codedread.com/scour/">Scour</a> Release Notes</h1> <h1><a href="http://codedread.com/scour/">Scour</a> Release Notes</h1>
<p>Copyright 2009, Jeff Schiller</p> <p>Copyright 2010, Jeff Schiller</p>
<section id="0.24"> <section id="0.24">
<header> <header>
@ -16,6 +16,8 @@
<p>2010-02-04</p> <p>2010-02-04</p>
<ul> <ul>
<li>Fix <a href="https://bugs.launchpad.net/scour/+bug/517064">Bug 517064</a> to make XML well-formed again</li> <li>Fix <a href="https://bugs.launchpad.net/scour/+bug/517064">Bug 517064</a> to make XML well-formed again</li>
<li>Fix <a href="https://bugs.launchpad.net/scour/+bug/503750">Bug 503750</a> fix Inkscape extension to correctly pass --enable-viewboxing</li>
<li>Fix <a href="https://bugs.launchpad.net/scour/+bug/511186">Bug 511186</a> fix stripping of comments outside of the root &lt;svg&gt; node</li>
</ul> </ul>
</section> </section>

View file

@ -34,8 +34,8 @@
# at rounded corners) # at rounded corners)
# Next Up: # 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 # - only remove unreferenced elements if they are not children of a referenced element
# - TODO: fix the removal of comment elements (between <?xml?> and <svg>)
# - add an option to remove ids if they match the Inkscape-style of IDs # - add an option to remove ids if they match the Inkscape-style of IDs
# - investigate point-reducing algorithms # - investigate point-reducing algorithms
# - parse transform attribute # - parse transform attribute
@ -2289,13 +2289,20 @@ def scourString(in_string, options=None):
if line.strip(): if line.strip():
lines.append(line) 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: if options.strip_xml_prolog == False:
xmlprolog = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' + os.linesep total_output = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' + os.linesep
else: 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 += ('<!--' + child.nodeValue + '-->' + os.linesep)
else:
total_output += "".join(lines)
return xmlprolog + "".join(lines) return total_output
# used mostly by unit tests # used mostly by unit tests
# input is a filename # input is a filename

View file

@ -987,7 +987,16 @@ class XmlEntities(unittest.TestCase):
def runTest(self): def runTest(self):
self.assertEquals( scour.makeWellFormed('<>&"\''), '&lt;&gt;&amp;&quot;&apos;', self.assertEquals( scour.makeWellFormed('<>&"\''), '&lt;&gt;&amp;&quot;&apos;',
'Incorrectly translated XML entities') '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 tests for --enable-viewboxing
# 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