XML Formatter QoL improvements #88
@@ -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:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user