Changeset 33523 for branches/3.9/src/wp-includes/formatting.php
- Timestamp:
- 07/31/2015 01:44:04 AM (10 years ago)
- File:
-
- 1 edited
-
branches/3.9/src/wp-includes/formatting.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/3.9/src/wp-includes/formatting.php
r33386 r33523 292 292 $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines 293 293 294 // Strip newlines from all elements.295 $pee = wp_replace_in_html_tags( $pee, array( "\n" => " " ) );294 // Find newlines in all elements and add placeholders. 295 $pee = wp_replace_in_html_tags( $pee, array( "\n" => " <!-- wpnl --> " ) ); 296 296 297 297 if ( strpos( $pee, '</object>' ) !== false ) { … … 340 340 $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee); 341 341 342 // Restore newlines in all elements. 343 $pee = str_replace( " <!-- wpnl --> ", "\n", $pee ); 344 342 345 return $pee; 346 } 347 348 /** 349 * Separate HTML elements and comments from the text. 350 * 351 * @since 4.2.4 352 * 353 * @param string $input The text which has to be formatted. 354 * @return array The formatted text. 355 */ 356 function wp_html_split( $input ) { 357 static $regex; 358 359 if ( ! isset( $regex ) ) { 360 $comments = 361 '!' // Start of comment, after the <. 362 . '(?:' // Unroll the loop: Consume everything until --> is found. 363 . '-(?!->)' // Dash not followed by end of comment. 364 . '[^\-]*+' // Consume non-dashes. 365 . ')*+' // Loop possessively. 366 . '(?:-->)?'; // End of comment. If not found, match all input. 367 368 $cdata = 369 '!\[CDATA\[' // Start of comment, after the <. 370 . '[^\]]*+' // Consume non-]. 371 . '(?:' // Unroll the loop: Consume everything until ]]> is found. 372 . '](?!]>)' // One ] not followed by end of comment. 373 . '[^\]]*+' // Consume non-]. 374 . ')*+' // Loop possessively. 375 . '(?:]]>)?'; // End of comment. If not found, match all input. 376 377 $regex = 378 '/(' // Capture the entire match. 379 . '<' // Find start of element. 380 . '(?(?=!--)' // Is this a comment? 381 . $comments // Find end of comment. 382 . '|' 383 . '(?(?=!\[CDATA\[)' // Is this a comment? 384 . $cdata // Find end of comment. 385 . '|' 386 . '[^>]*>?' // Find end of element. If not found, match all input. 387 . ')' 388 . ')' 389 . ')/s'; 390 } 391 392 return preg_split( $regex, $input, -1, PREG_SPLIT_DELIM_CAPTURE ); 343 393 } 344 394 … … 354 404 function wp_replace_in_html_tags( $haystack, $replace_pairs ) { 355 405 // Find all elements. 356 $comments = 357 '!' // Start of comment, after the <. 358 . '(?:' // Unroll the loop: Consume everything until --> is found. 359 . '-(?!->)' // Dash not followed by end of comment. 360 . '[^\-]*+' // Consume non-dashes. 361 . ')*+' // Loop possessively. 362 . '(?:-->)?'; // End of comment. If not found, match all input. 363 364 $regex = 365 '/(' // Capture the entire match. 366 . '<' // Find start of element. 367 . '(?(?=!--)' // Is this a comment? 368 . $comments // Find end of comment. 369 . '|' 370 . '[^>]*>?' // Find end of element. If not found, match all input. 371 . ')' 372 . ')/s'; 373 374 $textarr = preg_split( $regex, $haystack, -1, PREG_SPLIT_DELIM_CAPTURE ); 406 $textarr = wp_html_split( $haystack ); 375 407 $changed = false; 376 408
Note: See TracChangeset
for help on using the changeset viewer.