Skip to content

Instantly share code, notes, and snippets.

@yujinqiu
Forked from joac/indent_ET.py
Created July 21, 2013 02:30
Show Gist options
  • Select an option

  • Save yujinqiu/6047250 to your computer and use it in GitHub Desktop.

Select an option

Save yujinqiu/6047250 to your computer and use it in GitHub Desktop.
def indent(elem, level=0):
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment