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