Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

Pretty-print SVG file (Issue #33) #67

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions termtosvg/anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,25 @@ def make_animated_group(records, time, duration, cell_height, cell_width, defs):

return animation_group_tag, new_definitions

def indent(elem, level=0):
# From http://effbot.org/zone/element-lib.htm#prettyprint
i = "\n" + level*" "
if len(elem):
if not elem.text or not elem.text.strip():
elem.text = i + " "
if not elem.tail or not elem.tail.strip():
elem.tail = i
for elem in elem:
indent(elem, level+1)
if not elem.tail or not elem.tail.strip():
elem.tail = i
else:
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i

def render_animation(records, filename, template, cell_width=8, cell_height=17):
root = _render_animation(records, template, cell_width, cell_height)
indent(root)
with open(filename, 'wb') as output_file:
output_file.write(etree.tostring(root))

Expand Down