Skip to content

Commit

Permalink
Merge pull request #352 from wordpress-mobile/gutenberg/remove-videop…
Browse files Browse the repository at this point in the history
…ress-ref-from-excerpt

Remove Gutenberg Video block from excerpt to hide VideoPress URLs
  • Loading branch information
Siobhan Bamber authored Mar 1, 2024
2 parents 2298da4 + 586a6be commit 0a14bc9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ extension String {
return removingMatches(pattern: pattern, options: .caseInsensitive)
}

/// Strips Gutenberg VideoPress block.
/// Strips VideoPress references from Gutenberg VideoPress and Video blocks.
///
private func strippingGutenbergVideoPress() -> String {
let pattern = "(?s)\n?<!--\\swp:videopress/video?(.*?)wp:videopress/video\\s-->"
let pattern = "(?s)\n?<!--\\swp:video.*?(.*?)wp:video.*?\\s-->"

return removingMatches(pattern: pattern, options: .caseInsensitive)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,13 @@ class StringStripGutenbergContentForExcerptTests: XCTestCase {

XCTAssertEqual(summary, expectedSummary)
}

func testStrippingGutenbergContentForExcerptWithVideoPress2() {
let content = "<p>Before</p>\n<!-- wp:video {\"guid\":\"AbCDe\",\"id\":5297} -->\n<figure class=\"wp-block-video\"><div class=\"wp-block-embed__wrapper\">\nhttps://videopress.com/v/AbCDe?resizeToParent=true&amp;cover=true&amp;preloadContent=metadata&amp;useAverageColor=true\n</div></figure>\n<!-- /wp:video -->\n<p>After</p>"
let expectedSummary = "<p>Before</p>\n<p>After</p>"

let summary = content.strippingGutenbergContentForExcerpt()

XCTAssertEqual(summary, expectedSummary)
}
}

0 comments on commit 0a14bc9

Please sign in to comment.