1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 import sys, inkex
4 from scour import scourString
6 class ScourInkscape (inkex.Effect):
8 def __init__(self):
9 inkex.Effect.__init__(self)
10 self.OptionParser.add_option("--tab",
11 action="store", type="string",
12 dest="tab")
13 self.OptionParser.add_option("--simplify-colors", type="inkbool",
14 action="store", dest="simple_colors", default=True,
15 help="won't convert all colors to #RRGGBB format")
16 self.OptionParser.add_option("--style-to-xml", type="inkbool",
17 action="store", dest="style_to_xml", default=True,
18 help="won't convert styles into XML attributes")
19 self.OptionParser.add_option("--group-collapsing", type="inkbool",
20 action="store", dest="group_collapse", default=True,
21 help="won't collapse <g> elements")
22 self.OptionParser.add_option("--enable-id-stripping", type="inkbool",
23 action="store", dest="strip_ids", default=False,
24 help="remove all un-referenced ID attributes")
25 self.OptionParser.add_option("--embed-rasters", type="inkbool",
26 action="store", dest="embed_rasters", default=True,
27 help="won't embed rasters as base64-encoded data")
28 self.OptionParser.add_option("--keep-editor-data", type="inkbool",
29 action="store", dest="keep_editor_data", default=False,
30 help="won't remove Inkscape, Sodipodi or Adobe Illustrator elements and attributes")
31 self.OptionParser.add_option("--strip-xml-prolog", type="inkbool",
32 action="store", dest="strip_xml_prolog", default=False,
33 help="won't output the <?xml ?> prolog")
34 self.OptionParser.add_option("-p", "--set-precision",
35 action="store", type=int, dest="digits", default=5,
36 help="set number of significant digits (default: %default)")
37 self.OptionParser.add_option("--indent",
38 action="store", type="string", dest="indent_type", default="space",
39 help="indentation of the output: none, space, tab (default: %default)")
40 self.OptionParser.add_option("--enable-viewboxing", type="inkbool",
41 action="store", dest="enable_viewboxing", default=False,
42 help="changes document width/height to 100%/100% and creates viewbox coordinates")
45 def effect(self):
46 input = file(self.args[0], "r")
47 sys.stdout.write(scourString(input.read(), self.options).encode("UTF-8"))
48 input.close()
49 sys.stdout.close()
52 if __name__ == '__main__':
53 e = ScourInkscape()
54 e.affect(output=False)