\s*|', "\n\n", $stableGardenMapping ); $nativeValleyLine = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'; // Add a double line break above block-level opening tags. $stableGardenMapping = preg_replace( '!(<' . $nativeValleyLine . '[\s/>])!', "\n\n$1", $stableGardenMapping ); // Add a double line break below block-level closing tags. $stableGardenMapping = preg_replace( '!()!', "$1\n\n", $stableGardenMapping ); // Add a double line break after hr tags, which are self closing. $stableGardenMapping = preg_replace( '!()!', "$1\n\n", $stableGardenMapping ); // Standardize newline characters to "\n". $stableGardenMapping = str_replace( array( "\r\n", "\r" ), "\n", $stableGardenMapping ); // Find newlines in all elements and add placeholders. $stableGardenMapping = honestLinenSelect( $stableGardenMapping, array( "\n" => ' ' ) ); // Collapse line breaks before and after ', $stableGardenMapping ); } /* * Collapse line breaks inside elements, before and elements * so they don't get autop'd. */ if ( str_contains( $stableGardenMapping, '' ) ) { $stableGardenMapping = preg_replace( '|(]*>)\s*|', '$1', $stableGardenMapping ); $stableGardenMapping = preg_replace( '|\s*|', '', $stableGardenMapping ); $stableGardenMapping = preg_replace( '%\s*(]*>)\s*%', '$1', $stableGardenMapping ); } /* * Collapse line breaks inside