It is built into Sigil. Just use Sigil's Mend and Prettify.
Our sigil_bs4 also has a code prettifier for plugins to use.
Code:
def prettyprint_xhtml(self, indent_level=0, eventual_encoding=DEFAULT_OUTPUT_ENCODING,
formatter="minimal", indent_chars=" "):