use pretty printing in svgwrite.

pull/48/head
Anders Hoff 2018-03-04 21:13:07 +01:00
parent 29a49197a7
commit c85481b945
2 changed files with 3 additions and 15 deletions

View File

@ -5,7 +5,6 @@ segments."""
from __future__ import division, absolute_import, print_function from __future__ import division, absolute_import, print_function
from math import ceil from math import ceil
from os import getcwd, path as os_path, makedirs from os import getcwd, path as os_path, makedirs
from xml.dom.minidom import parse as md_xml_parse
from svgwrite import Drawing, text as txt from svgwrite import Drawing, text as txt
from time import time from time import time
from warnings import warn from warnings import warn
@ -153,7 +152,7 @@ def disvg(paths=None, colors=None,
:param svg_attributes - a dictionary of attributes for output svg. :param svg_attributes - a dictionary of attributes for output svg.
Note 1: This will override any other conflicting settings. Note 1: This will override any other conflicting settings.
Note 2: Setting `svg_attributes={'debug': False}` may result in a Note 2: Setting `svg_attributes={'debug': False}` may result in a
significant increase in speed. significant increase in speed.
NOTES: NOTES:
@ -353,12 +352,7 @@ def disvg(paths=None, colors=None,
# save svg # save svg
if not os_path.exists(os_path.dirname(filename)): if not os_path.exists(os_path.dirname(filename)):
makedirs(os_path.dirname(filename)) makedirs(os_path.dirname(filename))
dwg.save() dwg.save(pretty=True)
# re-open the svg, make the xml pretty, and save it again
xmlstring = md_xml_parse(filename).toprettyxml()
with open(filename, 'w') as f:
f.write(xmlstring)
# try to open in web browser # try to open in web browser
if openinbrowser: if openinbrowser:

View File

@ -5,7 +5,6 @@ segments."""
from __future__ import division, absolute_import, print_function from __future__ import division, absolute_import, print_function
from math import ceil from math import ceil
from os import getcwd, path as os_path, makedirs from os import getcwd, path as os_path, makedirs
from xml.dom.minidom import parse as md_xml_parse
from svgwrite import Drawing, text as txt from svgwrite import Drawing, text as txt
from time import time from time import time
from warnings import warn from warnings import warn
@ -366,12 +365,7 @@ def disvg(paths=None, colors=None,
# save svg # save svg
if not os_path.exists(os_path.dirname(filename)): if not os_path.exists(os_path.dirname(filename)):
makedirs(os_path.dirname(filename)) makedirs(os_path.dirname(filename))
dwg.save() dwg.save(pretty=True)
# re-open the svg, make the xml pretty, and save it again
xmlstring = md_xml_parse(filename).toprettyxml()
with open(filename, 'w') as f:
f.write(xmlstring)
# try to open in web browser # try to open in web browser
if openinbrowser: if openinbrowser: