Changeset 33522 for branches/4.0/src/wp-includes/formatting.php
- Timestamp:
- 07/31/2015 01:43:11 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.0/src/wp-includes/formatting.php
r33381 r33522 406 406 $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines 407 407 408 // Strip newlines from all elements.409 $pee = wp_replace_in_html_tags( $pee, array( "\n" => " " ) );408 // Find newlines in all elements and add placeholders. 409 $pee = wp_replace_in_html_tags( $pee, array( "\n" => " <!-- wpnl --> " ) ); 410 410 411 411 if ( strpos( $pee, '<option' ) !== false ) { … … 460 460 $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee); 461 461 462 // Restore newlines in all elements. 463 $pee = str_replace( " <!-- wpnl --> ", "\n", $pee ); 464 462 465 return $pee; 466 } 467 468 /** 469 * Separate HTML elements and comments from the text. 470 * 471 * @since 4.2.4 472 * 473 * @param string $input The text which has to be formatted. 474 * @return array The formatted text. 475 */ 476 function wp_html_split( $input ) { 477 static $regex; 478 479 if ( ! isset( $regex ) ) { 480 $comments = 481 '!' // Start of comment, after the <. 482 . '(?:' // Unroll the loop: Consume everything until --> is found. 483 . '-(?!->)' // Dash not followed by end of comment. 484 . '[^\-]*+' // Consume non-dashes. 485 . ')*+' // Loop possessively. 486 . '(?:-->)?'; // End of comment. If not found, match all input. 487 488 $cdata = 489 '!\[CDATA\[' // Start of comment, after the <. 490 . '[^\]]*+' // Consume non-]. 491 . '(?:' // Unroll the loop: Consume everything until ]]> is found. 492 . '](?!]>)' // One ] not followed by end of comment. 493 . '[^\]]*+' // Consume non-]. 494 . ')*+' // Loop possessively. 495 . '(?:]]>)?'; // End of comment. If not found, match all input. 496 497 $regex = 498 '/(' // Capture the entire match. 499 . '<' // Find start of element. 500 . '(?(?=!--)' // Is this a comment? 501 . $comments // Find end of comment. 502 . '|' 503 . '(?(?=!\[CDATA\[)' // Is this a comment? 504 . $cdata // Find end of comment. 505 . '|' 506 . '[^>]*>?' // Find end of element. If not found, match all input. 507 . ')' 508 . ')' 509 . ')/s'; 510 } 511 512 return preg_split( $regex, $input, -1, PREG_SPLIT_DELIM_CAPTURE ); 463 513 } 464 514 … … 474 524 function wp_replace_in_html_tags( $haystack, $replace_pairs ) { 475 525 // Find all elements. 476 $comments = 477 '!' // Start of comment, after the <. 478 . '(?:' // Unroll the loop: Consume everything until --> is found. 479 . '-(?!->)' // Dash not followed by end of comment. 480 . '[^\-]*+' // Consume non-dashes. 481 . ')*+' // Loop possessively. 482 . '(?:-->)?'; // End of comment. If not found, match all input. 483 484 $regex = 485 '/(' // Capture the entire match. 486 . '<' // Find start of element. 487 . '(?(?=!--)' // Is this a comment? 488 . $comments // Find end of comment. 489 . '|' 490 . '[^>]*>?' // Find end of element. If not found, match all input. 491 . ')' 492 . ')/s'; 493 494 $textarr = preg_split( $regex, $haystack, -1, PREG_SPLIT_DELIM_CAPTURE ); 526 $textarr = wp_html_split( $haystack ); 495 527 $changed = false; 496 528
Note: See TracChangeset
for help on using the changeset viewer.