Skip to content

Commit dc660f3

Browse files
committed
Improve <br> handling
1 parent 4bdf378 commit dc660f3

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

Modules/Sources/WordPressShared/Utility/GutenbergExcerptGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public struct GutenbergExcerptGenerator {
1616

1717
// Extract content while convering <br>, <br/>, <br /> to newlines first
1818
let rawText = String(content[tagEnd.upperBound..<pEnd.lowerBound])
19-
.replacingOccurrences(of: "<br\\s*/?>", with: " ", options: .regularExpression)
19+
.replacingOccurrences(of: "(<br\\s*/?>)+", with: " ", options: [.regularExpression, .caseInsensitive])
2020

2121
let range = NSRange(rawText.startIndex..., in: rawText)
2222
let text = (regex?.stringByReplacingMatches(in: rawText, options: [], range: range, withTemplate: "") ?? rawText)

Modules/Tests/WordPressSharedTests/GutenbergExcerptGeneratorTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ struct GutenbergPostExcerptGeneratorTests {
3333
}
3434

3535
@Test func testPostWithBRTags() {
36-
let content = #"<p class="wp-block-paragraph">Yes,<br>look behind<br>in remembrance and with gratitude.</p><p class="wp-block-paragraph">Then,<br>stay present,<br>or miss memories in the making.</p>"#
36+
let content = #"<p class="wp-block-paragraph">Yes,<br>look behind<br><br>in remembrance and with gratitude.</p><p class="wp-block-paragraph">Then,<br>stay present,<BR />or miss memories in the making.</p>"#
3737

3838
let summary = GutenbergExcerptGenerator.firstParagraph(from: content, maxLength: 150)
39-
print(summary)
4039
#expect(summary == "Yes, look behind in remembrance and with gratitude.")
4140
}
4241
}

0 commit comments

Comments
 (0)