Fix Bug 511186: Preserve comments surround <svg> root node
This commit is contained in:
parent
6147bb2085
commit
c835423e8f
3 changed files with 25 additions and 7 deletions
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
<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">
|
||||
<header>
|
||||
|
|
@ -16,6 +16,8 @@
|
|||
<p>2010-02-04</p>
|
||||
<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/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 <svg> node</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
|
|
|
|||
17
scour.py
17
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 <?xml?> and <svg>)
|
||||
# - 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 = '<?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:
|
||||
xmlprolog = ""
|
||||
total_output = ""
|
||||
|
||||
return xmlprolog + "".join(lines)
|
||||
# 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 total_output
|
||||
|
||||
# used mostly by unit tests
|
||||
# input is a filename
|
||||
|
|
|
|||
|
|
@ -988,6 +988,15 @@ class XmlEntities(unittest.TestCase):
|
|||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue