Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
Test areas will already keep the original formatting. Where formatting is "lost" it's simply because of how HTML works: extra whitespace is ignored. If you want the original formatting to be maintained when the HTML is rendered you need to convert spaces to HTML entities, CRLFs to <br/> tags, and so on.