diff --git a/CHANGELOG.md b/CHANGELOG.md index bb8996e..216d843 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,7 +38,7 @@ _None._ ### New Features -_None._ +- Strip Gutenberg VideoPress block for excerpt [#339] ### Bug Fixes diff --git a/Sources/WordPressShared/Utility/String+StripGutenbergContentForExcerpt.swift b/Sources/WordPressShared/Utility/String+StripGutenbergContentForExcerpt.swift index 6154922..71c9fe6 100644 --- a/Sources/WordPressShared/Utility/String+StripGutenbergContentForExcerpt.swift +++ b/Sources/WordPressShared/Utility/String+StripGutenbergContentForExcerpt.swift @@ -4,18 +4,26 @@ import Foundation /// shown when generating post excerpts. /// extension String { - + /// This method is the main entry point to generate excerpts for Gutenberg content. /// public func strippingGutenbergContentForExcerpt() -> String { - return strippingGutenbergGalleries() + return strippingGutenbergGalleries().strippingGutenbergVideoPress() } - + /// Strips Gutenberg galleries from strings. /// private func strippingGutenbergGalleries() -> String { let pattern = "(?s)" - + + return removingMatches(pattern: pattern, options: .caseInsensitive) + } + + /// Strips Gutenberg VideoPress block. + /// + private func strippingGutenbergVideoPress() -> String { + let pattern = "(?s)\n?" + return removingMatches(pattern: pattern, options: .caseInsensitive) } } diff --git a/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift b/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift index ab9599e..e73f269 100644 --- a/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift +++ b/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift @@ -2,31 +2,40 @@ import XCTest @testable import WordPressShared class StringStripGutenbergContentForExcerptTests: XCTestCase { - + func testStrippingGutenbergContentForExcerpt() { let content = "

Some Content

" let expectedSummary = "

Some Content

" - + let summary = content.strippingGutenbergContentForExcerpt() - + XCTAssertEqual(summary, expectedSummary) } - + func testStrippingGutenbergContentForExcerptWithGallery() { let content = "

Some Content

" let expectedSummary = "

Some Content

" - + let summary = content.strippingGutenbergContentForExcerpt() - + XCTAssertEqual(summary, expectedSummary) } - + func testStrippingGutenbergContentForExcerptWithGallery2() { let content = "

Before

\n

After

" let expectedSummary = "

Before

\n

After

" - + + let summary = content.strippingGutenbergContentForExcerpt() + + XCTAssertEqual(summary, expectedSummary) + } + + func testStrippingGutenbergContentForExcerptWithVideoPress() { + let content = "

Before

\n\n
\nhttps://videopress.com/v/AbCDe?resizeToParent=true&cover=true&preloadContent=metadata&useAverageColor=true\n
\n\n

After

" + let expectedSummary = "

Before

\n

After

" + let summary = content.strippingGutenbergContentForExcerpt() - + XCTAssertEqual(summary, expectedSummary) } }