Following code is an example of text placed into a textarea from a database.
This is how I would do it (demo):
$('.pane').val(function(i,v){ return v.replace(/\s+/g,' ').replace(/>(\s)\n<'); });