Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Framework: Strip comment demarcations in content filtering #5042

Merged
merged 1 commit into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ function do_blocks( $content ) {
// Append remaining unmatched content.
$rendered_content .= $content;

// Strip remaining block comment demarcations.
$rendered_content = preg_replace( '/<!--\s+\/?wp:.*?-->\r?\n?/m', '', $rendered_content );

return $rendered_content;
}
add_filter( 'the_content', 'do_blocks', 9 ); // BEFORE do_shortcode().
25 changes: 25 additions & 0 deletions phpunit/class-do-blocks-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* `do_blocks` rendering test
*
* @package Gutenberg
*/

/**
* Test do_blocks
*/
class Do_Blocks_Test extends WP_UnitTestCase {
/**
* Test do_blocks removes comment demarcations.
*
* @covers ::do_blocks
*/
function test_do_blocks_removes_comments() {
$original_html = file_get_contents( dirname( __FILE__ ) . '/fixtures/do-blocks-original.html' );
$expected_html = file_get_contents( dirname( __FILE__ ) . '/fixtures/do-blocks-expected.html' );

$actual_html = do_blocks( $original_html );

$this->assertEquals( $expected_html, $actual_html );
}
}
12 changes: 12 additions & 0 deletions phpunit/fixtures/do-blocks-expected.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<p>First Auto Paragraph</p>

<!--more-->

<p>First Gutenberg Paragraph</p>

<p>Second Auto Paragraph</p>


<p>Third Gutenberg Paragraph</p>

<p>Third Auto Paragraph</p>
17 changes: 17 additions & 0 deletions phpunit/fixtures/do-blocks-original.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<p>First Auto Paragraph</p>

<!--more-->

<!-- wp:core/paragraph -->
<p>First Gutenberg Paragraph</p>
<!-- /wp:core/paragraph -->

<p>Second Auto Paragraph</p>

<!-- wp:core/test-self-closing /-->

<!-- wp:core/paragraph -->
<p>Third Gutenberg Paragraph</p>
<!-- /wp:core/paragraph -->

<p>Third Auto Paragraph</p>