...Any idea why the WebHelp generation messes up the formatting?...
I'm sure this isn't the answer you are hoping to see. I know it will sound flippant, but I'm serious and sincere.
Just a guess here, but maybe because it really doesn't matter in the end?
I mean, after all, the pages will present and the end viewer will be oblivious and really won't notice or care how the underlying code appears as long as they see what is helpful in their view on the screen.
Why is it crucial to you to ensure the HTML is formatted in a specific way?
The thing is, you are using a tool to accomplish easily what you can't if you use something like Notepad to code your pages. So you have to accept a certain amount of allowing the tool to just do its thing with the code. Or you can fight it tooth and nail and find yourself constantly frustrated. For example, if I choose to use a circular saw to cut through lumber, I have to accept that it's going to leave behind evidence that a circular saw was used. If I dislike that and cannot live with it, I need to acquire a different tool or accept that I must take further action to sand away the evidence.
Helpful and Handy Links
Most, if not all, HTML editors do the same thing (it's a form of visual assistance, rather than being presented with long single lines that would force you to continually scroll horizontally).
As to your "need to correct the indentation and spaces for a "search-and-replace" script that I run after generation," you probably need a better find&replace tool, such as FAR, that can ignore all spaces.