+ return a.replace(/(\r\n|\n)/g, '<wp-temp-lb>');
+ });
+ }
+
+ // keep <br> tags inside captions and convert line breaks
+ if ( pee.indexOf('[caption') != -1 ) {
+ preserve_br = true;
+ pee = pee.replace(/\[caption[\s\S]+?\[\/caption\]/g, function(a) {
+ // keep existing <br>
+ a = a.replace(/<br([^>]*)>/g, '<wp-temp-br$1>');
+ // no line breaks inside HTML tags
+ a = a.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(b){
+ return b.replace(/[\r\n\t]+/, ' ');
+ });
+ // convert remaining line breaks to <br>
+ return a.replace(/\s*\n\s*/g, '<wp-temp-br />');