From 5621013e8a04bf062d05403b7a6bb91c9df8a865 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Tue, 13 Feb 2018 20:55:24 -0500 Subject: [PATCH] Framework: Strip comment demarcations in content filtering --- lib/blocks.php | 3 +++ phpunit/class-do-blocks-test.php | 25 ++++++++++++++++++++++++ phpunit/fixtures/do-blocks-expected.html | 12 ++++++++++++ phpunit/fixtures/do-blocks-original.html | 17 ++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 phpunit/class-do-blocks-test.php create mode 100644 phpunit/fixtures/do-blocks-expected.html create mode 100644 phpunit/fixtures/do-blocks-original.html diff --git a/lib/blocks.php b/lib/blocks.php index 1d7b76773d8eec..e28971bad032c2 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -199,6 +199,9 @@ function do_blocks( $content ) { // Append remaining unmatched content. $rendered_content .= $content; + // Strip remaining block comment demarcations. + $rendered_content = preg_replace( '/\r?\n?/m', '', $rendered_content ); + return $rendered_content; } add_filter( 'the_content', 'do_blocks', 9 ); // BEFORE do_shortcode(). diff --git a/phpunit/class-do-blocks-test.php b/phpunit/class-do-blocks-test.php new file mode 100644 index 00000000000000..ec7cd97c39bbdf --- /dev/null +++ b/phpunit/class-do-blocks-test.php @@ -0,0 +1,25 @@ +assertEquals( $expected_html, $actual_html ); + } +} diff --git a/phpunit/fixtures/do-blocks-expected.html b/phpunit/fixtures/do-blocks-expected.html new file mode 100644 index 00000000000000..89781ba3d31874 --- /dev/null +++ b/phpunit/fixtures/do-blocks-expected.html @@ -0,0 +1,12 @@ +

First Auto Paragraph

+ + + +

First Gutenberg Paragraph

+ +

Second Auto Paragraph

+ + +

Third Gutenberg Paragraph

+ +

Third Auto Paragraph

diff --git a/phpunit/fixtures/do-blocks-original.html b/phpunit/fixtures/do-blocks-original.html new file mode 100644 index 00000000000000..3707e7a857910d --- /dev/null +++ b/phpunit/fixtures/do-blocks-original.html @@ -0,0 +1,17 @@ +

First Auto Paragraph

+ + + + +

First Gutenberg Paragraph

+ + +

Second Auto Paragraph

+ + + + +

Third Gutenberg Paragraph

+ + +

Third Auto Paragraph