Ticket #25615: correct-wording-for-wpautop.patch
File correct-wording-for-wpautop.patch, 6.8 KB (added by , 11 years ago) |
---|
-
wp-includes/formatting.php
181 181 * 182 182 * @since 0.71 183 183 * 184 * @param string $ peeThe text which has to be formatted.184 * @param string $text The text which has to be formatted. 185 185 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true. 186 186 * @return string Text which has been converted into correct paragraph tags. 187 187 */ 188 function wpautop($ pee, $br = true) {188 function wpautop($text, $br = true) { 189 189 $pre_tags = array(); 190 190 191 if ( trim($ pee) === '' )191 if ( trim($text) === '' ) 192 192 return ''; 193 193 194 $ pee = $pee. "\n"; // just to make things a little easier, pad the end194 $text = $text . "\n"; // just to make things a little easier, pad the end 195 195 196 if ( strpos($ pee, '<pre') !== false ) {197 $ pee_parts = explode( '</pre>', $pee);198 $last_p ee = array_pop($pee_parts);199 $ pee= '';196 if ( strpos($text, '<pre') !== false ) { 197 $text_parts = explode( '</pre>', $text ); 198 $last_part = array_pop($text_parts); 199 $text = ''; 200 200 $i = 0; 201 201 202 foreach ( $ pee_parts as $pee_part ) {203 $start = strpos($ pee_part, '<pre');202 foreach ( $text_parts as $text_part ) { 203 $start = strpos($text_part, '<pre'); 204 204 205 205 // Malformed html? 206 206 if ( $start === false ) { 207 $ pee .= $pee_part;207 $text .= $text_part; 208 208 continue; 209 209 } 210 210 211 211 $name = "<pre wp-pre-tag-$i></pre>"; 212 $pre_tags[$name] = substr( $ pee_part, $start ) . '</pre>';212 $pre_tags[$name] = substr( $text_part, $start ) . '</pre>'; 213 213 214 $ pee .= substr( $pee_part, 0, $start ) . $name;214 $text .= substr( $text_part, 0, $start ) . $name; 215 215 $i++; 216 216 } 217 217 218 $ pee .= $last_pee;218 $text .= $last_part; 219 219 } 220 220 221 $ pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);221 $text = preg_replace('|<br />\s*<br />|', "\n\n", $text); 222 222 // Space things out a little 223 223 $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'; 224 $ pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);225 $ pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);226 $ pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines227 if ( strpos($ pee, '<object') !== false ) {228 $ pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param$1>", $pee); // no peeinside object/embed229 $ pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);224 $text = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $text); 225 $text = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $text); 226 $text = str_replace(array("\r\n", "\r"), "\n", $text); // cross-platform newlines 227 if ( strpos($text, '<object') !== false ) { 228 $text = preg_replace('|\s*<param([^>]*)>\s*|', "<param$1>", $text); // no paragraph inside object/embed 229 $text = preg_replace('|\s*</embed>\s*|', '</embed>', $text); 230 230 } 231 $ pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates231 $text = preg_replace("/\n\n+/", "\n\n", $text); // take care of duplicates 232 232 // make paragraphs, including one at the end 233 $ pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);234 $ pee= '';235 foreach ( $ pees as $tinkle)236 $ pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";237 $ pee = preg_replace('|<p>\s*</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace238 $ pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $pee);239 $ pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag240 $ pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists241 $ pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);242 $ pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);243 $ pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);244 $ pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);233 $texts = preg_split('/\n\s*\n/', $text, -1, PREG_SPLIT_NO_EMPTY); 234 $text = ''; 235 foreach ( $texts as $paragraph ) 236 $text .= '<p>' . trim($paragraph, "\n") . "</p>\n"; 237 $text = preg_replace('|<p>\s*</p>|', '', $text); // under certain strange conditions it could create a P of entirely whitespace 238 $text = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $text); 239 $text = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $text); // don't wrap blocks 240 $text = preg_replace("|<p>(<li.+?)</p>|", "$1", $text); // problem with nested lists 241 $text = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $text); 242 $text = str_replace('</blockquote></p>', '</p></blockquote>', $text); 243 $text = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $text); 244 $text = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $text); 245 245 if ( $br ) { 246 $ pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee);247 $ pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks248 $ pee = str_replace('<WPPreserveNewline />', "\n", $pee);246 $text = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $text); 247 $text = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $text); // optionally make line breaks 248 $text = str_replace('<WPPreserveNewline />', "\n", $text); 249 249 } 250 $ pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee);251 $ pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);252 $ pee = preg_replace( "|\n</p>$|", '</p>', $pee);250 $text = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $text); 251 $text = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $text); 252 $text = preg_replace( "|\n</p>$|", '</p>', $text ); 253 253 254 254 if ( !empty($pre_tags) ) 255 $ pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);255 $text = str_replace(array_keys($pre_tags), array_values($pre_tags), $text); 256 256 257 return $ pee;257 return $text; 258 258 } 259 259 260 260 /** … … 277 277 * 278 278 * @since 2.9.0 279 279 * 280 * @param string $ peeThe content.280 * @param string $text The content. 281 281 * @return string The filtered content. 282 282 */ 283 function shortcode_unautop( $ pee) {283 function shortcode_unautop( $text ) { 284 284 global $shortcode_tags; 285 285 286 286 if ( empty( $shortcode_tags ) || !is_array( $shortcode_tags ) ) { 287 return $ pee;287 return $text; 288 288 } 289 289 290 290 $tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) ); … … 321 321 . '<\\/p>' // closing paragraph 322 322 . '/s'; 323 323 324 return preg_replace( $pattern, '$1', $ pee);324 return preg_replace( $pattern, '$1', $text ); 325 325 } 326 326 327 327 /**