Formatter now accepts XMLs with prologs

This commit is contained in:
2023-02-23 10:42:10 +01:00
parent 8083d7fa63
commit a95c745ae2

View File

@@ -7,8 +7,15 @@ def prettify(source: str) -> str:
:param source: XML
:return: prettified XML
"""
prolog = ""
prolog_start = source.find("<?")
if prolog_start != -1:
prolog_end = source.find("?>") + 2
prolog = source[prolog_start:prolog_end] + "\n"
source = source[prolog_end: ]
xml = etree.XML(source)
return etree.tostring(xml, pretty_print=True).decode()
return prolog + etree.tostring(xml, pretty_print=True).decode()
def minimize(source: str) -> str:
"""Method used to minimize XML by deleting not needed whitespaces.