Is it reading the web page, parsing it into an AST, sanitizing the AST, then writing it out? I have a similar function on my site: https://roastidio.us
There are 2 caveats:
* There are broken HTML files that somehow still work with a browser.
* There are web pages that rely on javascript even for the main text.