Final scour 0.18: more fixes to XML serialization (wellformedness), some unit tests, update to package script to use zip file and to package the inkscape extension
This commit is contained in:
parent
5f5c8a431d
commit
eb2a7a05ac
6 changed files with 60 additions and 7 deletions
25
scour.py
25
scour.py
|
|
@ -1876,6 +1876,23 @@ def remapNamespacePrefix(node, oldprefix, newprefix):
|
|||
for child in node.childNodes :
|
||||
remapNamespacePrefix(child, oldprefix, newprefix)
|
||||
|
||||
def makeWellFormed(str):
|
||||
newstr = str
|
||||
|
||||
# encode & as & ( must do this first so that < does not become &lt; )
|
||||
if str.find('&') != -1:
|
||||
newstr = str.replace('&', '&')
|
||||
|
||||
# encode < as <
|
||||
if str.find("<") != -1:
|
||||
newstr = str.replace('<', '<')
|
||||
|
||||
# encode > as > (TODO: is this necessary?)
|
||||
if str.find('>') != -1:
|
||||
newstr = str.replace('>', '>')
|
||||
|
||||
return newstr
|
||||
|
||||
# hand-rolled serialization function that has the following benefits:
|
||||
# - pretty printing
|
||||
# - somewhat judicious use of whitespace
|
||||
|
|
@ -1912,7 +1929,9 @@ def serializeXML(element, options, ind = 0):
|
|||
if attr.nodeValue.find('"') != -1:
|
||||
quot = "'"
|
||||
|
||||
outString += ' ' + attr.nodeName + '=' + quot + attr.nodeValue + quot
|
||||
attrValue = makeWellFormed( attr.nodeValue )
|
||||
|
||||
outString += ' ' + attr.nodeName + '=' + quot + attrValue + quot
|
||||
|
||||
# if no children, self-close
|
||||
children = element.childNodes
|
||||
|
|
@ -1930,9 +1949,9 @@ def serializeXML(element, options, ind = 0):
|
|||
# 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"]:
|
||||
outString += child.nodeValue
|
||||
outString += makeWellFormed(child.nodeValue)
|
||||
else:
|
||||
outString += child.nodeValue.strip()
|
||||
outString += makeWellFormed(child.nodeValue.strip())
|
||||
# CDATA node
|
||||
elif child.nodeType == 4:
|
||||
outString += '<![CDATA[' + child.nodeValue + ']]>'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue