diff options
| author | Nicolas Dufour <nicoduf@yahoo.fr> | 2010-02-05 22:38:46 +0000 |
|---|---|---|
| committer | JazzyNico <nicoduf@yahoo.fr> | 2010-02-05 22:38:46 +0000 |
| commit | 7dc13d6cf63a83d685c76aa6f12058f7b8570427 (patch) | |
| tree | 2aa9c2cb0f9ebc30119833f33cd7054b5a8d8fe3 /share/extensions | |
| parent | Translations: Farsi translation update (now 2%) (diff) | |
| download | inkscape-7dc13d6cf63a83d685c76aa6f12058f7b8570427.tar.gz inkscape-7dc13d6cf63a83d685c76aa6f12058f7b8570427.zip | |
Extensions. Scour update (0.24)
(bzr r9058)
Diffstat (limited to 'share/extensions')
| -rwxr-xr-x | share/extensions/scour.py | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/share/extensions/scour.py b/share/extensions/scour.py index b2b2c178e..b851e48c3 100755 --- a/share/extensions/scour.py +++ b/share/extensions/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 @@ -72,7 +72,7 @@ except ImportError: pass APP = 'scour' -VER = '0.23' +VER = '0.24' COPYRIGHT = 'Copyright Jeff Schiller, 2010' NS = { 'SVG': 'http://www.w3.org/2000/svg', @@ -2021,21 +2021,17 @@ def remapNamespacePrefix(node, 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('&', '&') + xml_ents = { '<':'<', '>':'>', '&':'&', "'":''', '"':'"'} + +# starr = [] +# for c in str: +# if c in xml_ents: +# starr.append(xml_ents[c]) +# else: +# starr.append(c) - # encode < as < - if str.find("<") != -1: - newstr = str.replace('<', '<') - - # encode > as > (TODO: is this necessary?) - if str.find('>') != -1: - newstr = str.replace('>', '>') - - return newstr + # this list comprehension is short-form for the above for-loop: + return ''.join([xml_ents[c] if c in xml_ents else c for c in str]) # hand-rolled serialization function that has the following benefits: # - pretty printing @@ -2295,13 +2291,19 @@ 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 = "" + + for child in doc.childNodes: + if child.nodeType == 1: + total_output += "".join(lines) + else: # doctypes, entities, comments + total_output += child.toxml() + os.linesep - return xmlprolog + "".join(lines) + return total_output # used mostly by unit tests # input is a filename |
