I want to remove new lines from some html (with php) except in
tags where whitespace is obviously important.
Split the content up. This is easily done with...
$blocks = preg_split('/<(|\/)pre>/', $html);
Just be careful, because the $blocks elements won't contain the pre opening and closing tags. I feel that assume the HTML is valid is acceptable, and therefore you can expect the pre-blocks to be every other element in the array (1, 3, 5, ...). Easily tested with $i % 2 == 1.
Example "complete" script (modify as you need to)...
test
Title
This is an article about...
line one
line two
line three
random