diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 13fd350b62..ddce906aa6 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -469,7 +469,7 @@ function wpautop( $pee, $br = true ) { $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)'; // Add a single line break above block-level opening tags. - $pee = preg_replace('!(<' . $allblocks . '[\s/>])!', "\n$1", $pee); + $pee = preg_replace('!(<' . $allblocks . '[\s/>])!', "\n\n$1", $pee); // Add a double line break below block-level closing tags. $pee = preg_replace('!()!', "$1\n\n", $pee); diff --git a/tests/phpunit/tests/formatting/Autop.php b/tests/phpunit/tests/formatting/Autop.php index ccc0d3ac48..62251d78ca 100644 --- a/tests/phpunit/tests/formatting/Autop.php +++ b/tests/phpunit/tests/formatting/Autop.php @@ -524,4 +524,14 @@ line 2
$this->assertEquals( $expected, trim( wpautop( $content ) ) ); } + + /** + * @ticket 4857 + */ + function test_that_text_before_blocks_is_peed() { + $content = 'a
b
'; + $expected = "

a

\n
b
"; + + $this->assertEquals( $expected, trim( wpautop( $content ) ) ); + } }