XML Formatter QoL improvements #88

Merged
bema merged 7 commits from bema/ref/formatter_reliability_ref into master 2023-03-01 12:40:32 +01:00
Showing only changes of commit 8a863b7650 - Show all commits

View File

@@ -25,18 +25,18 @@ def minimize(source: str) -> str:
:param source: XML
:return: minimized XML
"""
result = source
to_remove = [" ", " ", "\t", "\n"]
to_substitute = [(" <", "<"), ("> ", ">"), ("</ ", "</"), (" >", ">")]
prolog = ""
prolog_start = source.find("<?")
for chars in to_remove:
result = result.replace(chars, "")
if prolog_start != -1:
prolog_end = source.find("?>") + 2
prolog = source[prolog_start:prolog_end]
source = source[prolog_end: ]
for e in to_substitute:
result = result.replace(e[0], e[1])
return result
parser = etree.XMLParser(remove_blank_text=True)
xml = etree.fromstring(source, parser=parser)
return prolog + etree.tostring(xml, pretty_print=False).decode()
def xpath(source: str, xpath: str) -> str: