From 6ac974db267f871f4d4a6afa2be5c0ca3816adae Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Tue, 31 Dec 2024 17:09:49 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Stop=20beehiv=20blog=20style=20s?= =?UTF-8?q?lipping=20into=20summaries?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RSCore/Sources/RSCore/Shared/String+RSCore.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/RSCore/Sources/RSCore/Shared/String+RSCore.swift b/RSCore/Sources/RSCore/Shared/String+RSCore.swift index 612f4fe60..1c5add27b 100644 --- a/RSCore/Sources/RSCore/Shared/String+RSCore.swift +++ b/RSCore/Sources/RSCore/Shared/String+RSCore.swift @@ -195,7 +195,15 @@ public extension String { /// /// - Note: Doesn't work correctly with nested tags of the same name. private func removingTagAndContents(_ tag: String) -> String { - return self.replacingOccurrences(of: "<\(tag).+?", with: "", options: [.regularExpression, .caseInsensitive]) + let pattern = "<\(tag)>.*?<\\/\(tag)>" + if let regex = try? NSRegularExpression(pattern: pattern, options: [.dotMatchesLineSeparators, .caseInsensitive]) { + let range = NSRange(location: 0, length: self.utf16.count) + let modifiedString = regex.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: "") + return modifiedString + } else { + // If the above regex fails, fall back to the original method. + return self.replacingOccurrences(of: "<\(tag).+?", with: "", options: [.regularExpression, .caseInsensitive]) + } } /// Strips HTML from a string.