Make WordPress Core

Ticket #37672: 37672.diff

File 37672.diff, 1.8 KB (added by MattyRob, 8 years ago)
  • src/wp-includes/formatting.php

     
    474474        // Add a double line break below block-level closing tags.
    475475        $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
    476476
     477        // Treat <div> as special and put a new line below opening tags and above closing tags
     478        $pee = preg_replace('!(<div>)!', "$1\n", $pee);
     479        $pee = preg_replace('!(</div>)!', "\n$1", $pee);
     480
    477481        // Standardize newline characters to "\n".
    478482        $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    479483
     
    523530        // Under certain strange conditions it could create a P of entirely whitespace.
    524531        $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    525532
     533        // Remove the space we added to the <div> tag
     534        $pee = preg_replace("!(<div>)[/\n]+!", "$1", $pee);
     535        $pee = preg_replace("![/\n]+(</div>)!", "$1", $pee);
     536
    526537        // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    527538        $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $pee);
    528539
  • tests/phpunit/tests/formatting/Autop.php

     
    534532
    535533                $this->assertEquals( $expected, trim( wpautop( $content ) ) );
    536534        }
     535
     536        /**
     537         * @ticket 37672
     538         */
     539        function test_that_div_content_is_correctly_peed() {
     540                $content = "<div>\nThis is a paragraph.\n\nThis is another paragraph.\n</div>";
     541                $expected = "<div>\n<p>This is a paragraph.</p>\n<p>This is another paragraph.</p>\n</div>";
     542
     543                $this->assertEquals( $expected, trim( wpautop( $content ) ) );
     544        }
    537545}