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
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
SCOURVER="0.18"
|
SCOURVER="0.18"
|
||||||
cd ..
|
cd ..
|
||||||
tar cvf scour/tarballs/scour-$SCOURVER.tar scour/scour.py scour/svg_regex.py scour/LICENSE scour/NOTICE scour/README.txt scour/release-notes.html
|
zip scour/tarballs/scour-$SCOURVER.zip scour/scour.py scour/svg_regex.py scour/LICENSE scour/NOTICE scour/README.txt scour/release-notes.html
|
||||||
gzip scour/tarballs/scour-$SCOURVER.tar
|
|
||||||
cd scour
|
cd scour
|
||||||
|
zip tarballs/scour-inkscape-extension-$SCOURVER.zip scour.inx scour.inkscape.py scour.py svg_regex.py
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,11 @@
|
||||||
<header>
|
<header>
|
||||||
<h2><a href="#0.18">Version 0.18</a></h2>
|
<h2><a href="#0.18">Version 0.18</a></h2>
|
||||||
</header>
|
</header>
|
||||||
<p>Aug 5th, 2009</p>
|
<p>Aug 9th, 2009</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Remove attributes of gradients if they contain default values</li>
|
<li>Remove attributes of gradients if they contain default values</li>
|
||||||
<li>Reduce bezier/quadratic (c/q) segments to their shorthand equivalents (s/t)</li>
|
<li>Reduce bezier/quadratic (c/q) segments to their shorthand equivalents (s/t)</li>
|
||||||
<li>Custom XML serialization such that id/xml:id is printed first (Thanks to Richard Hutch for the suggestion)</li>
|
<li>Move to a custom XML serialization such that id/xml:id is printed first (Thanks to Richard Hutch for the suggestion)</li>
|
||||||
<li>Added --indent option to specify indentation type (default='space', other options: 'none', 'tab')</li>
|
<li>Added --indent option to specify indentation type (default='space', other options: 'none', 'tab')</li>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
25
scour.py
25
scour.py
|
|
@ -1876,6 +1876,23 @@ def remapNamespacePrefix(node, oldprefix, newprefix):
|
||||||
for child in node.childNodes :
|
for child in node.childNodes :
|
||||||
remapNamespacePrefix(child, oldprefix, newprefix)
|
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:
|
# hand-rolled serialization function that has the following benefits:
|
||||||
# - pretty printing
|
# - pretty printing
|
||||||
# - somewhat judicious use of whitespace
|
# - somewhat judicious use of whitespace
|
||||||
|
|
@ -1912,7 +1929,9 @@ def serializeXML(element, options, ind = 0):
|
||||||
if attr.nodeValue.find('"') != -1:
|
if attr.nodeValue.find('"') != -1:
|
||||||
quot = "'"
|
quot = "'"
|
||||||
|
|
||||||
outString += ' ' + attr.nodeName + '=' + quot + attr.nodeValue + quot
|
attrValue = makeWellFormed( attr.nodeValue )
|
||||||
|
|
||||||
|
outString += ' ' + attr.nodeName + '=' + quot + attrValue + quot
|
||||||
|
|
||||||
# if no children, self-close
|
# if no children, self-close
|
||||||
children = element.childNodes
|
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
|
# trim it only in the case of not being a child of an element
|
||||||
# where whitespace might be important
|
# where whitespace might be important
|
||||||
if element.nodeName in ["text", "tspan", "textPath", "tref", "title", "desc", "textArea"]:
|
if element.nodeName in ["text", "tspan", "textPath", "tref", "title", "desc", "textArea"]:
|
||||||
outString += child.nodeValue
|
outString += makeWellFormed(child.nodeValue)
|
||||||
else:
|
else:
|
||||||
outString += child.nodeValue.strip()
|
outString += makeWellFormed(child.nodeValue.strip())
|
||||||
# CDATA node
|
# CDATA node
|
||||||
elif child.nodeType == 4:
|
elif child.nodeType == 4:
|
||||||
outString += '<![CDATA[' + child.nodeValue + ']]>'
|
outString += '<![CDATA[' + child.nodeValue + ']]>'
|
||||||
|
|
|
||||||
1
scra.py
1
scra.py
|
|
@ -87,6 +87,7 @@ class ScourOptions:
|
||||||
embed_rasters = False
|
embed_rasters = False
|
||||||
keep_editor_data = False
|
keep_editor_data = False
|
||||||
strip_xml_prolog = False
|
strip_xml_prolog = False
|
||||||
|
indent_type = "space"
|
||||||
|
|
||||||
# params are the form elements (if a checkbox is unchecked it will not be present)
|
# params are the form elements (if a checkbox is unchecked it will not be present)
|
||||||
def fetch(req, indoc,**params):
|
def fetch(req, indoc,**params):
|
||||||
|
|
|
||||||
24
testscour.py
24
testscour.py
|
|
@ -833,6 +833,30 @@ class CDATAInXml(unittest.TestCase):
|
||||||
</svg>''',
|
</svg>''',
|
||||||
'Improperly serialized the cdata unit tests')
|
'Improperly serialized the cdata unit tests')
|
||||||
|
|
||||||
|
class WellFormedXMLLesserThanInAttrValue(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
wellformed = scour.scourString(open('unittests/xml-well-formed.svg').read())
|
||||||
|
self.assert_( wellformed.find('unicode="<"') != -1,
|
||||||
|
"Improperly serialized < in attribute value")
|
||||||
|
|
||||||
|
class WellFormedXMLAmpersandInAttrValue(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
wellformed = scour.scourString(open('unittests/xml-well-formed.svg').read())
|
||||||
|
self.assert_( wellformed.find('unicode="&"') != -1,
|
||||||
|
'Improperly serialized & in attribute value' )
|
||||||
|
|
||||||
|
class WellFormedXMLLesserThanInTextContent(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
wellformed = scour.scourString(open('unittests/xml-well-formed.svg').read())
|
||||||
|
self.assert_( wellformed.find('<title>2 < 5</title>') != -1,
|
||||||
|
'Improperly serialized < in text content')
|
||||||
|
|
||||||
|
class WellFormedXMLAmpersandInTextContent(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
wellformed = scour.scourString(open('unittests/xml-well-formed.svg').read())
|
||||||
|
self.assert_( wellformed.find('<desc>Peanut Butter & Jelly</desc>') != -1,
|
||||||
|
'Improperly serialized & in text content')
|
||||||
|
|
||||||
# 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
|
||||||
# TODO: write tests for --keep-editor-data
|
# TODO: write tests for --keep-editor-data
|
||||||
|
|
|
||||||
9
unittests/xml-well-formed.svg
Normal file
9
unittests/xml-well-formed.svg
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<!-- <Jack & Jill> -->
|
||||||
|
<title>2 < 5</title>
|
||||||
|
<desc>Peanut Butter & Jelly</desc>
|
||||||
|
<glyph id="lt" unicode="<"/>
|
||||||
|
<glyph id="amp" unicode="&"/>
|
||||||
|
<text x="50" y="50">ΉTML & CSS</text>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 320 B |
Loading…
Add table
Add a link
Reference in a new issue