Changeset 33518 for branches/4.2/src/wp-includes/formatting.php
- Timestamp:
- 07/30/2015 07:40:33 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.2/src/wp-includes/formatting.php
r33360 r33518 420 420 421 421 // Standardize newline characters to "\n". 422 $pee = str_replace(array("\r\n", "\r"), "\n", $pee); 423 424 // Strip newlines from all elements.425 $pee = wp_replace_in_html_tags( $pee, array( "\n" => " " ) );422 $pee = str_replace(array("\r\n", "\r"), "\n", $pee); 423 424 // Find newlines in all elements and add placeholders. 425 $pee = wp_replace_in_html_tags( $pee, array( "\n" => " <!-- wpnl --> " ) ); 426 426 427 427 // Collapse line breaks before and after <option> elements so they don't get autop'd. … … 510 510 $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee); 511 511 512 // Restore newlines in all elements. 513 $pee = str_replace( " <!-- wpnl --> ", "\n", $pee ); 514 512 515 return $pee; 516 } 517 518 /** 519 * Separate HTML elements and comments from the text. 520 * 521 * @since 4.2.4 522 * 523 * @param string $input The text which has to be formatted. 524 * @return array The formatted text. 525 */ 526 function wp_html_split( $input ) { 527 static $regex; 528 529 if ( ! isset( $regex ) ) { 530 $comments = 531 '!' // Start of comment, after the <. 532 . '(?:' // Unroll the loop: Consume everything until --> is found. 533 . '-(?!->)' // Dash not followed by end of comment. 534 . '[^\-]*+' // Consume non-dashes. 535 . ')*+' // Loop possessively. 536 . '(?:-->)?'; // End of comment. If not found, match all input. 537 538 $cdata = 539 '!\[CDATA\[' // Start of comment, after the <. 540 . '[^\]]*+' // Consume non-]. 541 . '(?:' // Unroll the loop: Consume everything until ]]> is found. 542 . '](?!]>)' // One ] not followed by end of comment. 543 . '[^\]]*+' // Consume non-]. 544 . ')*+' // Loop possessively. 545 . '(?:]]>)?'; // End of comment. If not found, match all input. 546 547 $regex = 548 '/(' // Capture the entire match. 549 . '<' // Find start of element. 550 . '(?(?=!--)' // Is this a comment? 551 . $comments // Find end of comment. 552 . '|' 553 . '(?(?=!\[CDATA\[)' // Is this a comment? 554 . $cdata // Find end of comment. 555 . '|' 556 . '[^>]*>?' // Find end of element. If not found, match all input. 557 . ')' 558 . ')' 559 . ')/s'; 560 } 561 562 return preg_split( $regex, $input, -1, PREG_SPLIT_DELIM_CAPTURE ); 513 563 } 514 564 … … 524 574 function wp_replace_in_html_tags( $haystack, $replace_pairs ) { 525 575 // Find all elements. 526 $comments = 527 '!' // Start of comment, after the <. 528 . '(?:' // Unroll the loop: Consume everything until --> is found. 529 . '-(?!->)' // Dash not followed by end of comment. 530 . '[^\-]*+' // Consume non-dashes. 531 . ')*+' // Loop possessively. 532 . '(?:-->)?'; // End of comment. If not found, match all input. 533 534 $regex = 535 '/(' // Capture the entire match. 536 . '<' // Find start of element. 537 . '(?(?=!--)' // Is this a comment? 538 . $comments // Find end of comment. 539 . '|' 540 . '[^>]*>?' // Find end of element. If not found, match all input. 541 . ')' 542 . ')/s'; 543 544 $textarr = preg_split( $regex, $haystack, -1, PREG_SPLIT_DELIM_CAPTURE ); 576 $textarr = wp_html_split( $haystack ); 545 577 $changed = false; 546 578
Note: See TracChangeset
for help on using the changeset viewer.