Ticket #38656: 38656.diff
File 38656.diff, 3.8 KB (added by , 8 years ago) |
---|
-
src/wp-includes/formatting.php
466 466 // Change multiple <br>s into two line breaks, which will turn into paragraphs. 467 467 $pee = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee); 468 468 469 $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'; 469 // Block level elements that can contain a <p>. 470 $peeblocks = 'caption|td|th|div|dd|dt|li|form|map|blockquote|address|fieldset|section|article|aside|header|footer|nav|figure|figcaption|details|menu'; 471 472 // Block level elements that cannot contain a <p>. 473 $peefreeblocks = 'table|thead|tfoot|col|colgroup|tbody|tr|dl|ul|ol|pre|area|math|style|p|h[1-6]|hr|legend|hgroup|summary'; 474 475 $allblocks = "(?:$peeblocks|$peefreeblocks)"; 476 $peeblocks = "(?:$peeblocks)"; 477 $peefreeblocks = "(?:$peefreeblocks)"; 478 479 // Preserve newlines within pee-free blocks. 480 $pee = preg_replace_callback('/<(' . $peefreeblocks . ')( [^>]*)?>.*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee); 481 482 // ... but not the ones inside pee blocks inside pee free blocks. 483 $pee = preg_replace( '%(<(' . $peeblocks . ")(?: [^>]*)?>)>(.*?)<WPPreserveNewline />(.*?)(</\\2>)%s", "$1$3\n$4$5", $pee ); 470 484 471 485 // Add a double line break above block-level opening tags. 472 486 $pee = preg_replace('!(<' . $allblocks . '[\s/>])!', "\n\n$1", $pee); … … 474 488 // Add a double line break below block-level closing tags. 475 489 $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee); 476 490 491 // Add a double line break below block-level opening tags that are allowed to contain a <p>. 492 $pee = preg_replace('%(<' . $peeblocks . '(?: [^>]*)?>)%', "$1\n\n", $pee); 493 494 // Add a double line break above block-level closing tags that are allowed to contain a <p>. 495 $pee = preg_replace('%(</' . $peeblocks . '>)%', "\n\n$1", $pee); 496 477 497 // Standardize newline characters to "\n". 478 498 $pee = str_replace(array("\r\n", "\r"), "\n", $pee); 479 499 … … 506 526 $pee = preg_replace( '%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee ); 507 527 } 508 528 529 // If there's only one paragraph inside a pee block, remove the newlines. 530 $pee = preg_replace( '%(<(' . $peeblocks . ")(?: [^>]*)?>)\n\n((?(?!\n\n).)*)\n\n(</\\2>)%s", '$1$3$4', $pee ); 531 509 532 // Remove more than two contiguous line breaks. 510 533 $pee = preg_replace("/\n\n+/", "\n\n", $pee); 511 534 … … 520 543 $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n"; 521 544 } 522 545 546 // Replace newline placeholders with newlines. 547 $pee = str_replace('<WPPreserveNewline />', "\n", $pee); 548 523 549 // Under certain strange conditions it could create a P of entirely whitespace. 524 550 $pee = preg_replace('|<p>\s*</p>|', '', $pee); 525 551 -
tests/phpunit/tests/formatting/Autop.php
534 534 535 535 $this->assertEquals( $expected, trim( wpautop( $content ) ) ); 536 536 } 537 538 /** 539 * @ticket 38656 540 */ 541 function test_that_paragraphs_inside_blocks_without_starting_newlines_are_peed() { 542 $content = "<div>a\n\nb</div>"; 543 $expected = "<div>\n<p>a</p>\n<p>b</p>\n</div>"; 544 545 $this->assertEquals( $expected, trim( wpautop( $content ) ) ); 546 } 547 548 /** 549 * @ticket 38656 550 */ 551 function test_that_paragraphs_inside_non_pee_blocks_without_starting_newlines_are_not_peed() { 552 $content = "<h1>a\n\nb</h1>"; 553 $expected = "<h1>a<br />\nb</h1>"; 554 555 $this->assertEquals( $expected, trim( wpautop( $content ) ) ); 556 } 537 557 }