Last active
November 7, 2018 09:24
-
-
Save jiahut/e532f9d5c6a4a4b88fb234f874c19770 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #/usr/bin/env python | |
| import re | |
| import sys | |
| from xml.dom.minidom import parseString | |
| _xml_re = re.compile('>\n\s+([^<>\s].*?)\n\s+</', re.DOTALL) | |
| def pretty_xml_old(xml_str, indent=" "): | |
| xml_re = _xml_re | |
| # avoid re-prettifying large amounts of xml that is fine | |
| if xml_str.count("\n") < 20: | |
| pxml = parseString(xml_str).toprettyxml(indent) | |
| return xml_re.sub('>\g<1></', pxml) | |
| else: | |
| return xml_str | |
| if __name__ == '__main__': | |
| print(pretty_xml_old(sys.stdin.read())) |
Author
jiahut
commented
Nov 7, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment