Can you use regular expressions in Python? That would eliminate the need for hunting down all the whitespace or wrapping an if-then around stuff. You'd just have to check to see if you were in a preformatted space such as with the white-space

re css declaration or the <pre> tag. If you were, you ignored the collapsing of white space. If not, just change white space within tags to one (div, p, etc -- the block elements) using a regular expression search & replace...
Just an idea.
Good going with the addition of hanging indent!