Co-authored-by: mikolaj widla <mikolaj.widla@gmail.com>
Co-authored-by: Adam Bem <adam.bem@zoho.eu>
Reviewed-on: R11/release11-tools-web#81
This commit is contained in:
2023-02-28 11:46:54 +01:00
parent 28a9a1f670
commit 24c9c2fe5a
12 changed files with 141 additions and 64 deletions

View File

@@ -2,10 +2,27 @@ from lxml import etree
def prettify(source: str) -> str:
"""Method used to pretty format given XML
: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.
:param source: XML
:return: minimized XML
"""
result = source
to_remove = [" ", " ", "\t", "\n"]