From 99dfb0f8195964b156babe8a1c9e7625ff436199 Mon Sep 17 00:00:00 2001 From: JSCHILL1 Date: Fri, 6 Nov 2009 17:21:57 -0600 Subject: [PATCH] Fix whitespace collapsing when it shouldn't on non-textual elements that have xml:space=preserve --- release-notes.html | 1 + scour.py | 3 +-- testscour.py | 8 +++++++- unittests/no-collapse-lines.svg | 8 ++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 unittests/no-collapse-lines.svg diff --git a/release-notes.html b/release-notes.html index d67d6ca..f7fc35c 100644 --- a/release-notes.html +++ b/release-notes.html @@ -16,6 +16,7 @@

TBD

diff --git a/scour.py b/scour.py index 667945c..659b7a2 100755 --- a/scour.py +++ b/scour.py @@ -2098,8 +2098,7 @@ def serializeXML(element, options, ind = 0, preserveWhitespace = False): elif child.nodeType == 3: # trim it only in the case of not being a child of an element # where whitespace might be important - if element.nodeName in ["text", "tspan", "textPath", "tref", "title", "desc", "textArea", - "flowRoot", "flowDiv", "flowSpan", "flowPara", "flowRegion"]: + if preserveWhitespace: outString += makeWellFormed(child.nodeValue) else: outString += makeWellFormed(child.nodeValue.strip()) diff --git a/testscour.py b/testscour.py index 7c8322f..e0f49af 100755 --- a/testscour.py +++ b/testscour.py @@ -949,7 +949,13 @@ class GetAttrPrefixRight(unittest.TestCase): def runTest(self): grad = scour.scourXmlFile('unittests/xml-namespace-attrs.svg').getElementsByTagNameNS(SVGNS, 'linearGradient')[1] self.assertEquals( grad.getAttributeNS('http://www.w3.org/1999/xlink', 'href'), '#linearGradient841', - 'Did not get xlink:href prefix right' ) + 'Did not get xlink:href prefix right') + +class EnsurePreserveWhitespaceOnNonTextElements(unittest.TestCase): + def runTest(self): + s = scour.scourString(open('unittests/no-collapse-lines.svg').read()) + self.assertEquals( s.count('\n'), 5, + 'Did not properly preserve whitespace on elements even if they were not textual') # TODO; write a test for embedding rasters # TODO: write a test for --disable-embed-rasters diff --git a/unittests/no-collapse-lines.svg b/unittests/no-collapse-lines.svg new file mode 100644 index 0000000..85da385 --- /dev/null +++ b/unittests/no-collapse-lines.svg @@ -0,0 +1,8 @@ + + + + + +