The solution is simply "tidy"/Tidy-HTML. It will take your poorly formatted HTML code (and I mean files that span just a few lines that are unreadable) and fix it up.
Note the command below does everything in place. *Make sure you take a backup of all .html files*
It also seems to break html5 code/templates so beware.
tidy -im yourfile.html
An automated way in bash:
cd /your/website/directory
for html in `find .|grep ".html$"`; do
tidy -im $html
done
linux, reformat, html, solutionthe, quot, tidy, poorly, formatted, span, unreadable, templates, beware, im, yourfile, automated, bash, website, directory, grep,