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

Remove Gutenberg Video block from excerpt to hide VideoPress URLs #352

Merged
merged 3 commits into from
Mar 1, 2024
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
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)
}
}